QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#699183 | #7624. Mystery of Prime | Regina# | WA | 2ms | 9828kb | C++14 | 1.5kb | 2024-11-02 03:22:15 | 2024-11-02 03:22:15 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+10,inf=1e18;
int n,cnt,a[N],isp[N],f[N][5],pr[N];//set<pair<int,int> >s;
inline int read(){
int r=0,f=1;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c))r=(r<<1)+(r<<3)+(c^48),c=getchar();
return r*f;
}
void put(int x){
if(x<0){putchar('-');x=~x+1;}
if(x>9)put(x/10);
putchar(x%10+'0');
}
signed main(){
// freopen("cpp.in","r",stdin);
// freopen("cpp.out","w",stdout);
n=read(),isp[1]=1;
for(int i=1;i<=n;i++)a[i]=read();
for(int i=2;i<=2e5;i++){
if(!isp[i])pr[++cnt]=i;
for(int j=1;j<=cnt&&pr[j]*i<=2e5;j++){
isp[pr[j]*i]=1;
if(i%pr[j]==0)break;
}
}
for(int i=1;i<=n;i++){
f[i][1]=min(f[i-1][2],f[i-1][3])+1;
f[i][2]=min(f[i-1][2],f[i-1][1])+1;
if(!isp[a[i-1]+1])f[i][2]=min(f[i][2],f[i-1][4]+1);
f[i][3]=f[i-1][1]+1;
if(a[i-1]&1)f[i][1]=min(f[i][1],f[i-1][4]+1);
else f[i][3]=min(f[i][3],f[i-1][4]+1);
if(a[i]&1)f[i][4]=f[i-1][1];
else{
f[i][4]=f[i-1][3];
if(!isp[a[i]+1])f[i][4]=min(f[i][4],f[i-1][2]);
}
if(!isp[a[i]+a[i-1]])f[i][4]=min(f[i][4],f[i-1][4]);
}
// for(int i=1;i<=n;i++,putchar('\n'))for(int j=1;j<=4;j++)cout<<f[i][j]<<" ";
int ans=inf;
for(int i=1;i<=4;i++)ans=min(ans,f[n][i]);
return put(ans),puts(""),0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 7984kb
input:
6 1 5 1 4 4 1
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 2ms
memory: 9828kb
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: 2ms
memory: 7980kb
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:
761
result:
wrong answer 1st numbers differ - expected: '733', found: '761'