QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#684059#7624. Mystery of Primelanos212#WA 3ms9692kbC++20871b2024-10-28 09:44:512024-10-28 09:44:51

Judging History

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

  • [2024-10-28 09:44:51]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:9692kb
  • [2024-10-28 09:44:51]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;

int n,a[300001],f[300001],b[300001],mi=1e18;

signed main(){
ios::sync_with_stdio(false); cin.tie(0);

b[1]=1;
for (int i=2;i<=300000;++i) if (!b[i]) for (int j=i+i;j<=300000;j+=i) b[j]=1;

cin>>n;
for (int i=1;i<=n;++i) cin>>a[i];
for (int i=1;i<=n;++i){
f[i]=i-1;
if (i>=2 && !b[a[i]+a[i-1]]) f[i]=min(f[i],f[i-1]);
if (i>=3 && (abs(a[i]-a[i-2])%2==0 || (!b[a[i]+1] && !b[a[i-2]+1]))) f[i]=min(f[i],f[i-2]+1);
if (i>=4 && (abs(a[i]-a[i-3])%2==1 || a[i]==1 || a[i-3]==1 || (!b[a[i]+1] && !b[a[i-2]+1]))) f[i]=min(f[i],f[i-3]+2);
if (i>=5 && (abs(a[i]-a[i-4])%2==0 || !b[a[i]+1] || !b[a[i-4]+1])) f[i]=min(f[i],f[i-4]+3);
f[i]=min(f[i],mi+i-1);
if (i>=5) mi=min(mi,f[i-4]-(i-4));
}

int ans=1e18;
for (int i=1;i<=n;++i) ans=min(ans,f[i]+(n-i));
cout<<ans<<'\n';

return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 9412kb

input:

6
1 5 1 4 4 1

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

9
30 6 7 12 15 8 20 17 14

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 9692kb

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:

734

result:

wrong answer 1st numbers differ - expected: '733', found: '734'