結果
問題 | No.1646 Avoid Palindrome |
ユーザー | puzneko |
提出日時 | 2021-10-24 23:23:58 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,195 bytes |
コンパイル時間 | 256 ms |
コンパイル使用メモリ | 82,428 KB |
実行使用メモリ | 466,800 KB |
最終ジャッジ日時 | 2024-10-02 05:59:10 |
合計ジャッジ時間 | 60,515 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
60,616 KB |
testcase_01 | AC | 45 ms
60,564 KB |
testcase_02 | AC | 43 ms
59,936 KB |
testcase_03 | AC | 49 ms
63,996 KB |
testcase_04 | AC | 1,813 ms
443,756 KB |
testcase_05 | AC | 1,806 ms
443,740 KB |
testcase_06 | AC | 1,616 ms
431,008 KB |
testcase_07 | AC | 1,760 ms
444,356 KB |
testcase_08 | AC | 1,780 ms
447,724 KB |
testcase_09 | AC | 1,590 ms
429,008 KB |
testcase_10 | AC | 1,597 ms
437,864 KB |
testcase_11 | AC | 1,564 ms
427,400 KB |
testcase_12 | AC | 1,760 ms
443,480 KB |
testcase_13 | AC | 1,787 ms
447,564 KB |
testcase_14 | AC | 1,661 ms
436,944 KB |
testcase_15 | AC | 1,840 ms
444,832 KB |
testcase_16 | AC | 1,665 ms
434,328 KB |
testcase_17 | AC | 1,870 ms
450,752 KB |
testcase_18 | AC | 1,687 ms
440,056 KB |
testcase_19 | AC | 1,672 ms
438,500 KB |
testcase_20 | AC | 1,678 ms
441,280 KB |
testcase_21 | AC | 1,827 ms
450,352 KB |
testcase_22 | AC | 1,647 ms
437,280 KB |
testcase_23 | AC | 1,859 ms
452,564 KB |
testcase_24 | AC | 1,939 ms
466,768 KB |
testcase_25 | AC | 1,936 ms
466,496 KB |
testcase_26 | AC | 1,936 ms
466,772 KB |
testcase_27 | AC | 1,921 ms
466,800 KB |
testcase_28 | AC | 1,933 ms
466,672 KB |
testcase_29 | AC | 1,845 ms
466,560 KB |
testcase_30 | AC | 1,943 ms
466,472 KB |
testcase_31 | AC | 1,842 ms
466,692 KB |
testcase_32 | AC | 1,847 ms
466,560 KB |
testcase_33 | AC | 1,835 ms
466,644 KB |
testcase_34 | AC | 1,879 ms
465,980 KB |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | AC | 39 ms
58,536 KB |
testcase_38 | AC | 40 ms
57,788 KB |
testcase_39 | AC | 40 ms
58,032 KB |
testcase_40 | AC | 40 ms
58,348 KB |
testcase_41 | AC | 41 ms
59,052 KB |
testcase_42 | AC | 41 ms
58,336 KB |
testcase_43 | AC | 1,820 ms
466,492 KB |
ソースコード
n = int(input()) s = input() p = 998244353 alptonum = {"?":0,"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8,"i":9,"j":10,"k":11,"l":12,"m":13,"n":14,"o":15,"p":16,"q":17,"r":18,"s":19,"t":20,"u":21,"v":22,"w":23,"x":24,"y":25,"z":26} if n == 1: if s[i] == "?": print("{}".format(26)) else: print("{}".format(1)) exit() dp = [[[0 for k in range(27)] for i in range(27)] for j in range(n+1)] if s[0] == "?": for i in range(1,27): dp[1][0][i] = 1 else: dp[1][0][alptonum[s[0]]] = 1 for i in range(1,n): if s[i] == "?": for j in range(1,27): karisum = 0 for k in range(27): karisum = (karisum + dp[i][k][j]) % p for k in range(1,27): if j != k: dp[i+1][j][k] = (karisum - dp[i][k][j]) % p else: ind = alptonum[s[i]] for j in range(1,27): if j != ind: for k in range(27): if k != ind: dp[i+1][j][ind] = (dp[i+1][j][ind] + dp[i][k][j]) % p ans = 0 for i in range(1,27): for j in range(1,27): ans = (ans + dp[n][i][j]) % p print("{}".format(ans))