QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#247457 | #7619. Make SYSU Great Again I | ucup-team1525# | WA | 0ms | 8176kb | C++20 | 1.7kb | 2023-11-11 14:29:28 | 2023-11-11 14:29:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 50;
int is_pri[N];
void init()
{
memset(is_pri, -1, sizeof(is_pri));
for (int i = 2; i < N; i++)
{
if (is_pri[i] == -1)
is_pri[i] = 1;
for (int j = i * 2; j < N; j += i)
is_pri[j] = 0;
}
}
int n;
const int inf = 0x3f3f3f3f;
ll a[N];
int dp[N][4];
int main()
{
ios::sync_with_stdio(false), cin.tie(nullptr);
init();
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
memset(dp, inf, sizeof(dp));
dp[1][0] = 0;
dp[1][1] = (a[1] != 1);
dp[1][2] = (a[1] % 2);
dp[1][3] = (a[1] % 2 == 0 || a[1] == 1);
for (int i = 2; i <= n; i++)
{
if (is_pri[a[i] + a[i - 1]])
dp[i][0] = min(dp[i][0], dp[i - 1][0]);
if (is_pri[a[i - 1] + 1] && a[i] != 1)
dp[i][1] = min(dp[i][1], 1 + dp[i - 1][0]);
dp[i][3] = min(dp[i][3], dp[i - 1][2] + 1);
dp[i][2] = min(dp[i][2], dp[i - 1][3] + 1);
dp[i][2] = min(dp[i][2], dp[i - 1][1] + 1);
if (a[i] != 1)
dp[i][1] = min(dp[i][1], dp[i - 1][2] + 1);
if (a[i - 1] % 2 == 0)
{
dp[i][3] = min(dp[i][3], dp[i - 1][0] + 1);
if (is_pri[a[i] + 1])
dp[i][0] = min(dp[i][0], dp[i - 1][1]);
dp[i][0] = min(dp[i][0], dp[i - 1][3]);
}
else
{
dp[i][2] = min(dp[i][2], dp[i - 1][0] + 1);
dp[i][0] = min(dp[i][0], dp[i - 1][3]);
}
}
int ans = inf;
for (int j = 0; j < 4; j++)
ans = min(ans, dp[n][j]);
cout << ans << '\n';
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 8176kb
input:
3 6
output:
1
result:
wrong output format Unexpected end of file - int32 expected