QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#608133#7624. Mystery of PrimeDBsoleil#WA 2ms4364kbC++201.5kb2024-10-03 18:58:532024-10-03 18:58:55

Judging History

你现在查看的是最新测评结果

  • [2024-10-03 18:58:55]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4364kb
  • [2024-10-03 18:58:53]
  • 提交

answer

#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
typedef double db;

const int N=20005,K=15;
int n,a[N];
int dp[N][4];
int isp[N];
vector<int> ve;

void seive(int n)
{
    for(int i=2;i<=n;i++)
    {
        if(!isp[i]) ve.pb(i);
        for(int p:ve)
        {
            if(1ll*p*i>n) break;
            isp[p*i]=1;
            if(i%p==0) break;
        }
    }
}

void input()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
}

void upd(int&x,int y) {if(x>y) x=y;}

void solve()
{
    input();
    memset(dp,0x3f,sizeof(dp));
    dp[1][0]=0,dp[1][1]=dp[1][2]=dp[1][3]=1;
    for(int i=2;i<=n;i++)
    {
        if(!isp[a[i]+a[i-1]]) upd(dp[i][0],dp[i-1][0]);
        if(a[i]%2==0) upd(dp[i][0],dp[i-1][1]);
        else upd(dp[i][0],dp[i-1][2]);
        if(!isp[a[i]+1]) upd(dp[i][0],dp[i-1][3]);

        if(a[i-1]%2==0) upd(dp[i][1],dp[i-1][0]+1);
        upd(dp[i][1],dp[i-1][2]+1);

        if(a[i-1]%2) upd(dp[i][2],dp[i-1][0]+1);
        upd(dp[i][2],dp[i-1][1]+1);
        upd(dp[i][2],dp[i-1][3]+1);

        if(!isp[a[i-1]+1]) upd(dp[i][3],dp[i-1][0]+1);
        upd(dp[i][3],dp[i-1][2]+1);
        upd(dp[i][3],dp[i-1][3]+1);
        //cerr<<' '<<i<<' '<<dp[i][0]<<' '<<dp[i][1]<<' '<<dp[i][2]<<' '<<dp[i][3]<<endl;
    }
    int ans=n;
    for(int i=0;i<4;i++) upd(ans,dp[n][i]);
    printf("%d\n",ans);
}

int main()
{
    seive(N-5);
    solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4244kb

input:

6
1 5 1 4 4 1

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 1ms
memory: 4184kb

input:

9
30 6 7 12 15 8 20 17 14

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: 0
Accepted
time: 0ms
memory: 4196kb

input:

1568
119 519 706 1003 1317 322 25 1466 816 525 1 1122 38 1511 774 515 274 780 647 230 1602 1051 810 1 1 1232 1 1202 1583 412 1111 168 309 1181 184 1260 491 764 809 1213 804 1470 1 1087 1235 1004 673 1338 1333 1392 1036 1539 268 1 712 727 297 404 1317 36 463 1067 1133 693 931 46 1 100 1608 965 1 1406...

output:

733

result:

ok 1 number(s): "733"

Test #4:

score: 0
Accepted
time: 0ms
memory: 4196kb

input:

3261
489 1809 920 1061 1423 2330 420 1090 1387 1272 2238 979 1 2788 1885 1739 2291 1 1225 2076 2355 2008 1753 1438 2047 1148 1294 2179 2763 2074 1259 272 769 2104 2829 643 905 2155 2432 2328 1369 1 786 832 1 1775 885 867 803 2830 1 2088 2625 2735 2028 1489 105 1647 2844 2365 1521 1295 2318 2929 1 27...

output:

1501

result:

ok 1 number(s): "1501"

Test #5:

score: 0
Accepted
time: 1ms
memory: 4204kb

input:

4861
753 448 1399 1244 3435 3244 69 4110 3901 2335 3418 3242 2207 191 379 282 2896 1 1068 1 66 3517 1992 1 642 2103 3205 162 2971 1168 699 1972 1823 2856 2567 1772 246 2075 3623 1574 3105 2797 4121 1 3583 763 3567 3730 2043 2347 3483 8 347 405 1 1 3918 1270 2821 2566 1093 1586 683 3578 3879 1854 314...

output:

2283

result:

ok 1 number(s): "2283"

Test #6:

score: 0
Accepted
time: 1ms
memory: 4248kb

input:

6388
1 1372 1768 3823 1 1996 5172 3926 5734 1 5234 5219 4671 976 3880 4779 4721 5488 549 3080 1900 1001 1732 1129 4383 2071 4035 2798 1 1065 5222 65 351 1 2038 376 1 5423 3204 1 2256 3992 2365 5184 3522 1958 3969 5644 4263 3790 2064 3653 20 5103 5648 1404 14 2525 4306 796 4413 4018 1 4828 6013 1763 ...

output:

3015

result:

ok 1 number(s): "3015"

Test #7:

score: 0
Accepted
time: 1ms
memory: 4364kb

input:

7037
5377 66 1267 1689 3544 5122 5995 2503 1174 4380 1 4937 7077 3803 6290 82 3105 3612 2369 1 2214 4702 7575 3148 1 3569 3287 7882 3739 7306 2774 2088 1 7226 6299 6454 7485 310 3051 1 4663 6758 1606 6919 6609 7243 1984 6330 4339 7046 3909 4910 4131 3829 5722 1 6216 5827 2205 3580 2689 4030 1973 1 6...

output:

3297

result:

ok 1 number(s): "3297"

Test #8:

score: 0
Accepted
time: 2ms
memory: 4344kb

input:

9795
3928 1555 4412 1 5069 7890 2761 1 7087 4174 1976 1905 1 252 377 2654 9457 191 5272 7469 5598 1640 2139 3397 6892 2441 1234 4951 1803 1 1 3010 2584 1239 3550 422 1 1548 5321 4027 6445 6202 8609 2276 8255 6696 3612 1621 8256 9001 648 5181 7970 6694 9825 6934 1 2914 2347 1 4874 9396 312 2124 3409 ...

output:

4614

result:

ok 1 number(s): "4614"

Test #9:

score: -100
Wrong Answer
time: 2ms
memory: 4360kb

input:

11372
11482 11131 9002 7055 1 1 5112 11417 10956 1 4918 576 7024 8866 1 1 3060 840 9478 9925 3895 8076 2034 935 9528 11555 1598 3929 4598 2413 6404 6032 2255 1280 8715 4081 7197 6863 4464 4568 1 3466 7074 7813 1990 11019 4988 7173 6826 11271 2632 2223 530 6028 8215 10794 1122 5655 10912 2317 1926 19...

output:

5414

result:

wrong answer 1st numbers differ - expected: '5375', found: '5414'