提出 #60296093


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MOD = 998244353;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    ll ans = 0;
    for (int rev = 0; rev <= 1; rev++) {
        if (rev == 1) reverse(A.begin(), A.end());
        for (int g = 1; g < N; g++) {
            if (N % g != 0) continue;
            vector<ll> dp = {0}, c = {1};
            for (int k = 0; k < N; k++) {
                vector<ll> nxt_dp(k + 2), nxt_c(k + 2);
                for (int l = 0; l <= k; l++) {
                    // 1 → 0 の寄与
                    if (A[k] == 0 || A[k] == -1) {
                        nxt_dp[l + 1] += dp[l];
                        if (rev == 0) nxt_dp[l + 1] += (ll)((k - l - l % g + g - 1) / g) * k % MOD * c[l];
                        else nxt_dp[l + 1] += (ll)((k - l - l % g + g - 1) / g) * (N - 1 - k) % MOD * c[l];
                        nxt_dp[l + 1] %= MOD;
                        if (nxt_dp[l + 1] < 0) nxt_dp[l + 1] += MOD;
                        nxt_c[l + 1] += c[l];
                        nxt_c[l + 1] %= MOD;
                    }
                    // 0 → 1 の寄与
                    if (A[k] == 1 || A[k] == -1) {
                        nxt_dp[l] += dp[l];
                        if (rev == 0) nxt_dp[l] += (ll)((l - (k - l) % g + g - 1) / g) * k % MOD * c[l];
                        else nxt_dp[l] += (ll)((l - (k - l) % g + g - 1) / g) * (N - 1 - k) % MOD * c[l];
                        nxt_dp[l] %= MOD;
                        if (nxt_dp[l] < 0) nxt_dp[l] += MOD;
                        nxt_c[l] += c[l];
                        nxt_c[l] %= MOD;
                    }
                }
                swap(dp, nxt_dp);
                swap(c, nxt_c);
            }
            for (int alpha = 1; alpha <= N - 1; alpha++) {
                int beta = N - alpha;
                if (gcd(alpha, beta) == g) {
                    if (rev == 0) ans += dp[alpha];
                    else ans -= dp[alpha];
                    ans %= MOD;
                    if (ans < 0) ans += MOD;
                }
            }
        }
    }
    cout << ans << "\n";
}

提出情報

提出日時
問題 K - 01 Abs Sum
ユーザ otoshigo
言語 C++ 20 (gcc 12.2)
得点 100
コード長 2253 Byte
結果 AC
実行時間 2406 ms
メモリ 3872 KiB

ジャッジ結果

セット名 Sample Small Large
得点 / 配点 0 / 0 30 / 30 70 / 70
結果
AC × 3
AC × 21
AC × 53
セット名 テストケース
Sample sample-01.txt, sample-02.txt, sample-03.txt
Small sample-01.txt, sample-02.txt, sample-03.txt, small-01-01.txt, small-01-02.txt, small-02-01.txt, small-02-02.txt, small-03-01.txt, small-03-02.txt, small-04-01.txt, small-04-02.txt, small-05-01.txt, small-05-02.txt, small-06-01.txt, small-07-01.txt, small-07-02.txt, small-07-03.txt, small-08-01.txt, small-08-02.txt, small-09-01.txt, small-09-02.txt
Large handmade-01-01.txt, handmade-01-02.txt, handmade-01-03.txt, handmade-02-01.txt, handmade-02-02.txt, handmade-02-03.txt, handmade-03-01.txt, handmade-03-02.txt, handmade-03-03.txt, handmade-04-01.txt, handmade-04-02.txt, handmade-05-01.txt, handmade-05-02.txt, handmade-05-03.txt, random-06-01.txt, random-06-02.txt, random-06-03.txt, random-06-04.txt, random-06-05.txt, random-06-06.txt, random-07-01.txt, random-07-02.txt, random-08-01.txt, random-08-02.txt, random-08-03.txt, random-08-04.txt, random-08-05.txt, random-08-06.txt, random-09-01.txt, random-09-02.txt, random-09-03.txt, random-09-04.txt, sample-01.txt, sample-02.txt, sample-03.txt, small-01-01.txt, small-01-02.txt, small-02-01.txt, small-02-02.txt, small-03-01.txt, small-03-02.txt, small-04-01.txt, small-04-02.txt, small-05-01.txt, small-05-02.txt, small-06-01.txt, small-07-01.txt, small-07-02.txt, small-07-03.txt, small-08-01.txt, small-08-02.txt, small-09-01.txt, small-09-02.txt
ケース名 結果 実行時間 メモリ
handmade-01-01.txt AC 41 ms 3704 KiB
handmade-01-02.txt AC 41 ms 3804 KiB
handmade-01-03.txt AC 832 ms 3700 KiB
handmade-02-01.txt AC 1541 ms 3688 KiB
handmade-02-02.txt AC 2406 ms 3872 KiB
handmade-02-03.txt AC 2041 ms 3716 KiB
handmade-03-01.txt AC 2401 ms 3700 KiB
handmade-03-02.txt AC 2400 ms 3720 KiB
handmade-03-03.txt AC 2402 ms 3740 KiB
handmade-04-01.txt AC 3 ms 3644 KiB
handmade-04-02.txt AC 36 ms 3744 KiB
handmade-05-01.txt AC 222 ms 3648 KiB
handmade-05-02.txt AC 367 ms 3696 KiB
handmade-05-03.txt AC 7 ms 3836 KiB
random-06-01.txt AC 1 ms 3624 KiB
random-06-02.txt AC 39 ms 3652 KiB
random-06-03.txt AC 130 ms 3764 KiB
random-06-04.txt AC 61 ms 3728 KiB
random-06-05.txt AC 3 ms 3804 KiB
random-06-06.txt AC 261 ms 3648 KiB
random-07-01.txt AC 1051 ms 3724 KiB
random-07-02.txt AC 1067 ms 3764 KiB
random-08-01.txt AC 1639 ms 3660 KiB
random-08-02.txt AC 1653 ms 3760 KiB
random-08-03.txt AC 1660 ms 3696 KiB
random-08-04.txt AC 1416 ms 3676 KiB
random-08-05.txt AC 1406 ms 3684 KiB
random-08-06.txt AC 1410 ms 3696 KiB
random-09-01.txt AC 47 ms 3724 KiB
random-09-02.txt AC 48 ms 3720 KiB
random-09-03.txt AC 47 ms 3700 KiB
random-09-04.txt AC 46 ms 3724 KiB
sample-01.txt AC 1 ms 3484 KiB
sample-02.txt AC 1 ms 3476 KiB
sample-03.txt AC 1 ms 3504 KiB
small-01-01.txt AC 1 ms 3696 KiB
small-01-02.txt AC 1 ms 3612 KiB
small-02-01.txt AC 2 ms 3584 KiB
small-02-02.txt AC 3 ms 3556 KiB
small-03-01.txt AC 3 ms 3732 KiB
small-03-02.txt AC 2 ms 3576 KiB
small-04-01.txt AC 1 ms 3496 KiB
small-04-02.txt AC 1 ms 3676 KiB
small-05-01.txt AC 1 ms 3524 KiB
small-05-02.txt AC 1 ms 3568 KiB
small-06-01.txt AC 1 ms 3540 KiB
small-07-01.txt AC 1 ms 3560 KiB
small-07-02.txt AC 1 ms 3504 KiB
small-07-03.txt AC 2 ms 3648 KiB
small-08-01.txt AC 2 ms 3596 KiB
small-08-02.txt AC 2 ms 3572 KiB
small-09-01.txt AC 1 ms 3620 KiB
small-09-02.txt AC 1 ms 3616 KiB