結果
問題 | No.1646 Avoid Palindrome |
ユーザー | puzneko |
提出日時 | 2021-10-24 23:29:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,967 ms / 3,000 ms |
コード長 | 1,195 bytes |
コンパイル時間 | 341 ms |
コンパイル使用メモリ | 82,580 KB |
実行使用メモリ | 467,292 KB |
最終ジャッジ日時 | 2024-10-02 06:11:54 |
合計ジャッジ時間 | 59,439 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
62,172 KB |
testcase_01 | AC | 44 ms
61,712 KB |
testcase_02 | AC | 43 ms
60,232 KB |
testcase_03 | AC | 49 ms
63,796 KB |
testcase_04 | AC | 1,768 ms
443,784 KB |
testcase_05 | AC | 1,780 ms
443,672 KB |
testcase_06 | AC | 1,598 ms
430,632 KB |
testcase_07 | AC | 1,759 ms
444,008 KB |
testcase_08 | AC | 1,794 ms
448,460 KB |
testcase_09 | AC | 1,596 ms
428,824 KB |
testcase_10 | AC | 1,620 ms
437,980 KB |
testcase_11 | AC | 1,588 ms
427,220 KB |
testcase_12 | AC | 1,811 ms
443,356 KB |
testcase_13 | AC | 1,800 ms
447,720 KB |
testcase_14 | AC | 1,687 ms
437,100 KB |
testcase_15 | AC | 1,841 ms
444,416 KB |
testcase_16 | AC | 1,681 ms
434,984 KB |
testcase_17 | AC | 1,871 ms
450,936 KB |
testcase_18 | AC | 1,681 ms
440,188 KB |
testcase_19 | AC | 1,672 ms
438,488 KB |
testcase_20 | AC | 1,680 ms
441,196 KB |
testcase_21 | AC | 1,867 ms
450,888 KB |
testcase_22 | AC | 1,667 ms
437,528 KB |
testcase_23 | AC | 1,862 ms
452,524 KB |
testcase_24 | AC | 1,967 ms
467,292 KB |
testcase_25 | AC | 1,928 ms
466,752 KB |
testcase_26 | AC | 1,925 ms
467,016 KB |
testcase_27 | AC | 1,924 ms
466,696 KB |
testcase_28 | AC | 1,923 ms
466,696 KB |
testcase_29 | AC | 1,838 ms
466,852 KB |
testcase_30 | AC | 1,943 ms
466,872 KB |
testcase_31 | AC | 1,854 ms
466,580 KB |
testcase_32 | AC | 1,827 ms
466,752 KB |
testcase_33 | AC | 1,835 ms
466,700 KB |
testcase_34 | AC | 1,896 ms
466,120 KB |
testcase_35 | AC | 37 ms
53,264 KB |
testcase_36 | AC | 36 ms
53,032 KB |
testcase_37 | AC | 41 ms
57,920 KB |
testcase_38 | AC | 41 ms
59,060 KB |
testcase_39 | AC | 40 ms
58,164 KB |
testcase_40 | AC | 40 ms
57,860 KB |
testcase_41 | AC | 41 ms
58,812 KB |
testcase_42 | AC | 40 ms
59,872 KB |
testcase_43 | AC | 1,829 ms
466,728 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[0] == "?": 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))