提出 #41971551


ソースコード 拡げる

#include <iostream>
#include <vector>

using namespace std;

const int MOD = 998244353;

int countShifts(int N, const string& S) {
    // Count the number of '#'s in the original shift table
    int count = 0;
    for (char c : S) {
        if (c == '#') {
            count++;
        }
    }

    int result = 0;

    // Iterate over all possible divisors of N
    for (int M = 1; M * M <= N; M++) {
        if (N % M == 0) {
            // Calculate the number of shifts possible for this divisor M

            // Check if M is a valid divisor
            bool valid = true;
            for (int i = 0; i < M; i++) {
                for (int j = i + M; j < N; j += M) {
                    if (S[j] != S[i]) {
                        valid = false;
                        break;
                    }
                }
                if (!valid) {
                    break;
                }
            }

            if (valid) {
                // Calculate the number of possible shifts for this divisor
                int shifts = 1;
                for (int i = 0; i < count; i++) {
                    shifts = (shifts * 2) % MOD;
                }

                result = (result + shifts) % MOD;

                // Check if M is a proper divisor (not equal to N/M)
                if (M != N / M) {
                    valid = true;
                    for (int i = 0; i < N / M; i++) {
                        for (int j = i + N / M; j < N; j += N / M) {
                            if (S[j] != S[i]) {
                                valid = false;
                                break;
                            }
                        }
                        if (!valid) {
                            break;
                        }
                    }

                    if (valid) {
                        shifts = 1;
                        for (int i = 0; i < count; i++) {
                            shifts = (shifts * 2) % MOD;
                        }

                        result = (result + shifts) % MOD;
                    }
                }
            }
        }
    }

    return result;
}

int main() {
    int N;
    string S;
    cin >> N >> S;

    int result = countShifts(N, S);
    cout << result << endl;

    return 0;
}

提出情報

提出日時
問題 F - Shift Table
ユーザ chacoder
言語 C++ (GCC 9.2.1)
得点 0
コード長 2376 Byte
結果 WA
実行時間 48 ms
メモリ 3716 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 525
結果
WA × 3
WA × 49
セット名 テストケース
Sample sample00.txt, sample01.txt, sample02.txt
All sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt, testcase34.txt, testcase35.txt, testcase36.txt, testcase37.txt, testcase38.txt, testcase39.txt, testcase40.txt, testcase41.txt, testcase42.txt, testcase43.txt, testcase44.txt, testcase45.txt
ケース名 結果 実行時間 メモリ
sample00.txt WA 4 ms 3532 KiB
sample01.txt WA 3 ms 3404 KiB
sample02.txt WA 2 ms 3440 KiB
testcase00.txt WA 3 ms 3584 KiB
testcase01.txt WA 2 ms 3540 KiB
testcase02.txt WA 7 ms 3712 KiB
testcase03.txt WA 5 ms 3664 KiB
testcase04.txt WA 5 ms 3716 KiB
testcase05.txt WA 6 ms 3588 KiB
testcase06.txt WA 8 ms 3604 KiB
testcase07.txt WA 4 ms 3648 KiB
testcase08.txt WA 13 ms 3584 KiB
testcase09.txt WA 5 ms 3528 KiB
testcase10.txt WA 4 ms 3476 KiB
testcase11.txt WA 2 ms 3592 KiB
testcase12.txt WA 3 ms 3648 KiB
testcase13.txt WA 4 ms 3516 KiB
testcase14.txt WA 9 ms 3712 KiB
testcase15.txt WA 2 ms 3504 KiB
testcase16.txt WA 4 ms 3584 KiB
testcase17.txt WA 4 ms 3712 KiB
testcase18.txt WA 3 ms 3484 KiB
testcase19.txt WA 5 ms 3556 KiB
testcase20.txt WA 2 ms 3600 KiB
testcase21.txt WA 3 ms 3564 KiB
testcase22.txt WA 7 ms 3528 KiB
testcase23.txt WA 2 ms 3468 KiB
testcase24.txt WA 2 ms 3564 KiB
testcase25.txt WA 5 ms 3556 KiB
testcase26.txt WA 2 ms 3428 KiB
testcase27.txt WA 2 ms 3596 KiB
testcase28.txt WA 3 ms 3536 KiB
testcase29.txt WA 3 ms 3504 KiB
testcase30.txt WA 5 ms 3532 KiB
testcase31.txt WA 8 ms 3648 KiB
testcase32.txt WA 6 ms 3680 KiB
testcase33.txt WA 6 ms 3616 KiB
testcase34.txt WA 4 ms 3600 KiB
testcase35.txt WA 6 ms 3604 KiB
testcase36.txt WA 6 ms 3600 KiB
testcase37.txt WA 8 ms 3588 KiB
testcase38.txt WA 7 ms 3636 KiB
testcase39.txt WA 8 ms 3588 KiB
testcase40.txt WA 4 ms 3648 KiB
testcase41.txt WA 7 ms 3644 KiB
testcase42.txt WA 48 ms 3588 KiB
testcase43.txt WA 11 ms 3552 KiB
testcase44.txt WA 47 ms 3684 KiB
testcase45.txt WA 8 ms 3616 KiB