QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#281988 | #7624. Mystery of Prime | ucup-team2279 | WA | 14ms | 4420kb | C++14 | 763b | 2023-12-11 09:15:34 | 2023-12-11 09:15:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,a[N],b[N*2],f[N],f0[N],f1[N],g[N];
bool chk(int x){
for(int i=2;i*i<=x;i++) if(x%i==0) return 0;
return 1;
}
int main(){
cin.tie(0)->sync_with_stdio(0);
cin>>n;
for(int i=2;i<N*2;i++) b[i]=chk(i);
for(int i=1;i<=n;i++) cin>>a[i];
f0[1]=f1[1]=1;g[1]=a[1]!=1;
for(int i=2;i<=n;i++){
f[i]=a[i]%2?f0[i-1]:f1[i-1];
if(b[a[i]+1]) f[i]=min(f[i],g[i-1]);
if(b[a[i]+a[i-1]]) f[i]=min(f[i],f[i-1]);
f0[i]=min(f1[i-1],g[i-1]);
if(a[i-1]%2) f0[i]=min(f0[i],f[i-1]);
f1[i]=f0[i-1];
if(a[i-1]%2==0) f1[i]=min(f1[i],f[i-1]);
g[i]=min({g[i-1],f0[i-1],(!b[a[i]+1])*N+f[i-1]})+(a[i]!=1);
f0[i]++;f1[i]++;
}
cout<<min({f[n],f0[n],f1[n],g[n]});
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 14ms
memory: 4292kb
input:
6 1 5 1 4 4 1
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 14ms
memory: 4412kb
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: 14ms
memory: 4420kb
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:
663
result:
wrong answer 1st numbers differ - expected: '733', found: '663'