QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#247457#7619. Make SYSU Great Again Iucup-team1525#WA 0ms8176kbC++201.7kb2023-11-11 14:29:282023-11-11 14:29:29

Judging History

你现在查看的是最新测评结果

  • [2023-11-11 14:29:29]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:8176kb
  • [2023-11-11 14:29:28]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

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