結果
問題 | No.1646 Avoid Palindrome |
ユーザー | brthyyjp |
提出日時 | 2022-01-20 15:48:19 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,920 bytes |
コンパイル時間 | 212 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 78,720 KB |
最終ジャッジ日時 | 2024-05-03 00:59:17 |
合計ジャッジ時間 | 59,335 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
54,400 KB |
testcase_01 | AC | 46 ms
61,312 KB |
testcase_02 | AC | 46 ms
60,800 KB |
testcase_03 | AC | 55 ms
64,908 KB |
testcase_04 | AC | 1,286 ms
78,156 KB |
testcase_05 | WA | - |
testcase_06 | AC | 1,353 ms
78,388 KB |
testcase_07 | AC | 1,273 ms
78,052 KB |
testcase_08 | WA | - |
testcase_09 | AC | 1,281 ms
78,208 KB |
testcase_10 | AC | 1,375 ms
78,228 KB |
testcase_11 | AC | 1,276 ms
78,336 KB |
testcase_12 | AC | 1,347 ms
78,208 KB |
testcase_13 | WA | - |
testcase_14 | AC | 2,276 ms
78,476 KB |
testcase_15 | AC | 2,330 ms
78,452 KB |
testcase_16 | AC | 2,255 ms
78,196 KB |
testcase_17 | AC | 2,365 ms
78,328 KB |
testcase_18 | AC | 2,301 ms
78,332 KB |
testcase_19 | AC | 2,286 ms
78,392 KB |
testcase_20 | AC | 2,306 ms
78,592 KB |
testcase_21 | AC | 2,404 ms
78,444 KB |
testcase_22 | AC | 2,305 ms
78,336 KB |
testcase_23 | AC | 2,433 ms
78,460 KB |
testcase_24 | AC | 2,484 ms
78,660 KB |
testcase_25 | AC | 2,444 ms
78,592 KB |
testcase_26 | AC | 2,468 ms
78,592 KB |
testcase_27 | AC | 2,486 ms
78,320 KB |
testcase_28 | AC | 2,460 ms
78,664 KB |
testcase_29 | AC | 898 ms
78,028 KB |
testcase_30 | AC | 910 ms
78,128 KB |
testcase_31 | AC | 913 ms
78,076 KB |
testcase_32 | AC | 918 ms
78,412 KB |
testcase_33 | AC | 888 ms
78,264 KB |
testcase_34 | AC | 2,436 ms
77,824 KB |
testcase_35 | AC | 41 ms
53,888 KB |
testcase_36 | AC | 43 ms
54,016 KB |
testcase_37 | AC | 43 ms
54,016 KB |
testcase_38 | AC | 41 ms
54,272 KB |
testcase_39 | WA | - |
testcase_40 | AC | 42 ms
54,144 KB |
testcase_41 | AC | 43 ms
54,272 KB |
testcase_42 | AC | 42 ms
54,272 KB |
testcase_43 | WA | - |
ソースコード
import sys import io, os input = sys.stdin.readline from collections import Counter mod = 998244353 def main(): n = int(input()) s = str(input().rstrip()) if n == 1: if s[0] == '?': print(26) else: print(1) exit() dp = [0]*(26*26) if s[0] != '?' and s[1] != '?': c0 = ord(s[0])-ord('a') c1 = ord(s[0])-ord('a') dp[c1*26+c0] = 1 elif s[0] != '?': c0 = ord(s[0])-ord('a') for c1 in range(26): if c0 == c1: continue dp[c1*26+c0] = 1 elif s[1] != '?': c1 = ord(s[1])-ord('a') for c0 in range(26): if c0 == c1: continue dp[c1*26+c0] = 1 else: for c0 in range(26): for c1 in range(26): if c0 == c1: continue dp[c1*26+c0] = 1 for i in range(2, n): nx = [0]*(26*26) c = s[i] if c == '?': d1 = Counter() for c0 in range(26): for c1 in range(26): d1[c1] += dp[c1*26+c0] d1[c1] %= mod for c in range(26): for c1 in range(26): if c == c1: continue nx[c*26+c1] += d1[c1]-dp[c1*26+c] nx[c*26+c1] %= mod else: c = ord(c)-ord('a') for c0 in range(26): if c0 == c: continue for c1 in range(26): if c1 == c: continue nx[c*26+c1] += dp[c1*26+c0] nx[c*26+c1] %= mod dp = nx ans = 0 for c0 in range(26): for c1 in range(26): ans += dp[c1*26+c0] ans %= mod print(ans) if __name__ == '__main__': main()