結果

問題 No.1646 Avoid Palindrome
ユーザー H3PO4H3PO4
提出日時 2021-08-13 21:54:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,039 ms / 3,000 ms
コード長 751 bytes
コンパイル時間 453 ms
コンパイル使用メモリ 87,340 KB
実行使用メモリ 79,984 KB
最終ジャッジ日時 2023-08-08 09:34:57
合計ジャッジ時間 33,143 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
76,056 KB
testcase_01 AC 80 ms
76,472 KB
testcase_02 AC 82 ms
76,024 KB
testcase_03 AC 88 ms
76,888 KB
testcase_04 AC 846 ms
79,416 KB
testcase_05 AC 859 ms
79,356 KB
testcase_06 AC 836 ms
79,100 KB
testcase_07 AC 842 ms
79,368 KB
testcase_08 AC 855 ms
79,384 KB
testcase_09 AC 822 ms
79,204 KB
testcase_10 AC 835 ms
79,120 KB
testcase_11 AC 824 ms
79,196 KB
testcase_12 AC 840 ms
79,232 KB
testcase_13 AC 852 ms
79,212 KB
testcase_14 AC 982 ms
79,920 KB
testcase_15 AC 1,032 ms
79,548 KB
testcase_16 AC 963 ms
79,540 KB
testcase_17 AC 995 ms
79,560 KB
testcase_18 AC 981 ms
79,572 KB
testcase_19 AC 964 ms
79,668 KB
testcase_20 AC 982 ms
79,512 KB
testcase_21 AC 1,002 ms
79,656 KB
testcase_22 AC 963 ms
79,760 KB
testcase_23 AC 984 ms
79,488 KB
testcase_24 AC 1,029 ms
79,900 KB
testcase_25 AC 1,039 ms
79,984 KB
testcase_26 AC 1,032 ms
79,640 KB
testcase_27 AC 1,035 ms
79,640 KB
testcase_28 AC 1,032 ms
79,552 KB
testcase_29 AC 801 ms
79,384 KB
testcase_30 AC 812 ms
79,420 KB
testcase_31 AC 797 ms
79,204 KB
testcase_32 AC 797 ms
79,480 KB
testcase_33 AC 808 ms
79,604 KB
testcase_34 AC 1,000 ms
79,364 KB
testcase_35 AC 76 ms
75,320 KB
testcase_36 AC 75 ms
75,292 KB
testcase_37 AC 79 ms
76,120 KB
testcase_38 AC 78 ms
76,272 KB
testcase_39 AC 77 ms
76,180 KB
testcase_40 AC 77 ms
76,224 KB
testcase_41 AC 79 ms
76,108 KB
testcase_42 AC 78 ms
75,936 KB
testcase_43 AC 805 ms
79,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

en2asc = lambda s: ord(s) - 97

N = int(input())
S = input()

MOD = 998244353

dp = [[0] * 27 for _ in range(27)]
dp[-1][-1] = 1

for s in S:
    dp_sum = [sum(row) for row in dp]
    new_dp = [[0] * 27 for _ in range(27)]
    if s == '?':
        for i in range(26):
            for j in range(27):
                if i == j:
                    continue
                new_dp[i][j] += dp_sum[j] - dp[j][i]
    else:
        i = en2asc(s)
        for j in range(27):
            if i == j:
                continue
            new_dp[i][j] += dp_sum[j] - dp[j][i]

    dp = [[0] * 27 for _ in range(27)]
    for i in range(27):
        for j in range(27):
            dp[i][j] = new_dp[i][j] % MOD

ans = sum(sum(row) for row in dp) % MOD
print(ans)
0