QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#659317#7624. Mystery of PrimeYshanqianWA 4ms36796kbC++202.4kb2024-10-19 19:35:522024-10-19 19:35:53

Judging History

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

  • [2024-10-19 19:35:53]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:36796kb
  • [2024-10-19 19:35:52]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define xx first
#define yy second
#define endl "\n"
#define pb push_back
#define int long long
#define ll long long
#define lowbit(x) x & (-x)
typedef pair<int, int> pii;
#define LF(x) fixed << setprecision(x)
#define Yshanqian ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
const int N = 1e6 + 100, M = 1010, inf = 0x3f3f3f3f, mod = 1e9 + 7, P = 13331;
int n;
int a[N];
int dp[N][4];
bool st[N];
int cnt, p[N];
void init()
{
    int n = 2e5;
    st[1] = 1;
    for (int i = 2; i <= n; i++)
    {
        if (!st[i])
            p[++cnt] = i;
        for (int j = 1; p[j] <= n / i; j++)
        {
            st[i * p[j]] = 1;
            if (i % p[j] == 0)
                break;
        }
    }
}
void solve()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    memset(dp, inf, sizeof dp);
    dp[1][0] = 0; // 不变

    dp[1][1] = dp[1][2] = 1; // 变偶奇

    if (a[1] == 1)
        dp[1][3] = 0; // 变1
    else
        dp[1][3] = 1;

    for (int i = 2; i <= n; i++)
    {
        if (!st[a[i] + a[i - 1]])
            dp[i][0] = min(dp[i][0], dp[i - 1][0]);

        if (!st[a[i] + 1])
            dp[i][0] = min(dp[i][0], dp[i - 1][3]);

        int x = a[i] % 2;
        if (x)
            dp[i][0] = min(dp[i][0], dp[i - 1][1]);
        else
            dp[i][0] = min(dp[i][0], dp[i - 1][2]);

        dp[i][1] = min(dp[i][1], dp[i - 1][3] + 1);
        dp[i][1] = min(dp[i][1], dp[i - 1][2] + 1);
        if (a[i - 1] % 2 == 1)
            dp[i][1] = min(dp[i][1], dp[i - 1][0] + 1);

        dp[i][2] = min(dp[i][2], dp[i - 1][1] + 1);

        if (a[i - 1] % 2 == 0)
            dp[i][2] = min(dp[i][2], dp[i - 1][0] + 1);

        int add = 1;

        add = 0;

        if (!st[a[i - 1] + 1])
            dp[i][3] = min(dp[i][3], dp[i - 1][0] + add);

        dp[i][3] = min(dp[i][3], dp[i - 1][3] + add);

        dp[i][3] = min(dp[i][3], dp[i - 1][1] + add);
        if (a[i] == 1)
            dp[i][3] = min(dp[i][3], dp[i][0]);
    }

    int ans = inf;
    for (int i = 0; i <= 3; i++)
        ans = min(ans, dp[n][i]);
    cout << ans << endl;
}
signed main()
{
    Yshanqian;
    int T;
    T = 1;
    init();
    // cin >> T;
    for (int cases = 1; cases <= T; ++cases)
    {
        // cout<<"Case #"<<cases<<": ";
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 36796kb

input:

6
1 5 1 4 4 1

output:

0

result:

wrong answer 1st numbers differ - expected: '2', found: '0'