QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#684965 | #7624. Mystery of Prime | xcyyyyy | WA | 9ms | 12352kb | C++20 | 1.2kb | 2024-10-28 16:49:28 | 2024-10-28 16:49:29 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define N 100005
#define M 2000005
int n,a[N];
int pri[M],vis[M],f[N][4];
/* 0 不变,1 变为 1,2 变为偶数,3 变为奇数*/
void upd(int &x,int y){x=min(x,y);}
int main(){
for(int i=2;i<M;i++){
if(!vis[i])pri[++pri[0]]=i;
for(int j=1;pri[j]*i<M&&j<=pri[0];j++){
vis[pri[j]*i]=1;
if(i%pri[j]==0)break;
}
}
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
f[1][0]=0;f[1][1]=f[1][2]=f[1][3]=1;
for(int i=2;i<=n;i++){
for(int j=0;j<4;j++)f[i][j]=0x3f3f3f3f;
if(!vis[a[i-1]+a[i]])upd(f[i][0],f[i-1][0]);
if(a[i]==1)upd(f[i][0],f[i-1][1]);
if(a[i]&1)upd(f[i][0],f[i-1][2]);
if(~a[i]&1)upd(f[i][0],f[i-1][3]);
/*------------------------------*/
if(!vis[a[i-1]+1])upd(f[i][1],f[i-1][0]);
upd(f[i][1],f[i-1][1]);
upd(f[i][1],f[i-1][2]);
++f[i][1];
/*------------------------------*/
if(a[i-1]&1)upd(f[i][2],f[i-1][0]);
upd(f[i][2],f[i-1][1]);
upd(f[i][2],f[i-1][3]);
++f[i][2];
/*------------------------------*/
if(~a[i-1]&1)upd(f[i][3],f[i-1][0]);
upd(f[i][3],f[i-1][2]);
++f[i][3];
}
printf("%d\n",min({f[n][0],f[n][1],f[n][2],f[n][3]}));
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 6ms
memory: 12276kb
input:
6 1 5 1 4 4 1
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 9ms
memory: 12352kb
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: 8ms
memory: 12320kb
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:
745
result:
wrong answer 1st numbers differ - expected: '733', found: '745'