結果
問題 | No.1646 Avoid Palindrome |
ユーザー | aaaaaaaaaa2230 |
提出日時 | 2021-08-13 22:06:11 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,389 bytes |
コンパイル時間 | 261 ms |
コンパイル使用メモリ | 82,468 KB |
実行使用メモリ | 83,656 KB |
最終ジャッジ日時 | 2024-04-14 18:07:12 |
合計ジャッジ時間 | 14,967 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
59,684 KB |
testcase_01 | AC | 43 ms
57,832 KB |
testcase_02 | AC | 40 ms
58,764 KB |
testcase_03 | AC | 58 ms
66,084 KB |
testcase_04 | AC | 937 ms
76,452 KB |
testcase_05 | AC | 954 ms
76,296 KB |
testcase_06 | AC | 983 ms
76,404 KB |
testcase_07 | AC | 896 ms
76,192 KB |
testcase_08 | AC | 988 ms
76,400 KB |
testcase_09 | AC | 984 ms
76,620 KB |
testcase_10 | AC | 910 ms
76,288 KB |
testcase_11 | AC | 933 ms
76,244 KB |
testcase_12 | AC | 1,010 ms
76,160 KB |
testcase_13 | AC | 912 ms
76,176 KB |
testcase_14 | TLE | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
ソースコード
n = int(input()) S = input() mod = 998244353 dp = [0]*(26**2) if len(S) == 1: if S == "?": ans = 26 else: ans = 1 print(ans) exit() if S[0] == "?": if S[1] == "?": for i in range(26): for j in range(26): if i == j: continue dp[i*26+j] += 1 else: c = ord(S[1])-ord("a") for i in range(26): if i == c: continue dp[i*26+c] += 1 else: c = ord(S[0])-ord("a") if S[1] == "?": for j in range(26): if c == j: continue dp[c*26+j] += 1 else: c2 = ord(S[1])-ord("a") if c != c2: dp[c*26+c2] += 1 for s in S[2:]: ndp = [0]*(26**2) if s == "?": for i in range(26**2): if dp[i] == 0: continue x,y = divmod(i,26) for j in range(26): if y == j or x == j: continue ndp[y*26+j] += dp[i] ndp[y*26+j] %= mod else: c = ord(s)-ord("a") for i in range(26**2): if dp[i] == 0: continue x,y = divmod(i,26) if x == c or y == c: continue ndp[y*26+c] += dp[i] ndp[y*26+c] %= mod dp = ndp print(sum(dp)%mod)