結果
問題 | No.1646 Avoid Palindrome |
ユーザー | mkawa2 |
提出日時 | 2021-08-13 22:15:58 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,948 bytes |
コンパイル時間 | 361 ms |
コンパイル使用メモリ | 82,152 KB |
実行使用メモリ | 83,720 KB |
最終ジャッジ日時 | 2024-10-03 19:41:32 |
合計ジャッジ時間 | 18,669 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
66,888 KB |
testcase_01 | AC | 43 ms
59,412 KB |
testcase_02 | AC | 39 ms
52,768 KB |
testcase_03 | AC | 61 ms
68,184 KB |
testcase_04 | AC | 1,438 ms
76,728 KB |
testcase_05 | AC | 1,341 ms
76,508 KB |
testcase_06 | AC | 1,144 ms
76,684 KB |
testcase_07 | AC | 1,406 ms
76,668 KB |
testcase_08 | AC | 1,184 ms
76,532 KB |
testcase_09 | AC | 1,122 ms
76,624 KB |
testcase_10 | AC | 1,149 ms
76,656 KB |
testcase_11 | AC | 1,338 ms
76,672 KB |
testcase_12 | AC | 1,457 ms
76,960 KB |
testcase_13 | AC | 1,413 ms
77,144 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 | -- | - |
ソースコード
import sys sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = 10**16 md = 998244353 # md = 10**9+7 n = II() s = SI() if n == 1: if s[0] == "?": print(26) else: print(1) exit() for i in range(n-1): if s[i] != "?" and s[i] == s[i+1]: print(0) exit() for i in range(n-2): if s[i] != "?" and s[i] == s[i+2]: print(0) exit() dp = [[0]*26 for _ in range(26)] if s[0] == "?" and s[1] == "?": for i in range(26): for j in range(26): if i == j: continue dp[i][j] = 1 elif s[0] == "?": j = ord(s[1])-97 for i in range(26): if i == j: continue dp[i][j] = 1 elif s[1] == "?": i = ord(s[0])-97 for j in range(26): if i == j: continue dp[i][j] = 1 else: i = ord(s[0])-97 j = ord(s[1])-97 dp[i][j] = 1 def add(i, j, val): ndp[i][j] = (ndp[i][j]+val)%md for c in s[2:]: a = ord(c)-97 ndp = [[0]*26 for _ in range(26)] for i in range(26): for j in range(26): pre = dp[i][j] if pre == 0: continue if c == "?": for nj in range(26): if nj == i or nj == j: continue add(j, nj, pre) elif a != i and a != j: add(j, a, pre) dp = ndp ans = 0 for i in range(26): for j in range(26): ans += dp[i][j] ans %= md print(ans)