QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#684061 | #7624. Mystery of Prime | lanos212# | WA | 3ms | 9760kb | C++20 | 871b | 2024-10-28 09:46:35 | 2024-10-28 09:46:35 |
Judging History
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-3]+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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 9312kb
input:
6 1 5 1 4 4 1
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 8332kb
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: 3ms
memory: 8584kb
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: -100
Wrong Answer
time: 0ms
memory: 9760kb
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:
1499
result:
wrong answer 1st numbers differ - expected: '1501', found: '1499'