結果
問題 | No.1646 Avoid Palindrome |
ユーザー | mkawa2 |
提出日時 | 2021-08-14 05:58:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 785 ms / 3,000 ms |
コード長 | 1,891 bytes |
コンパイル時間 | 458 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 76,544 KB |
最終ジャッジ日時 | 2024-11-08 16:15:36 |
合計ジャッジ時間 | 22,201 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
59,392 KB |
testcase_01 | AC | 47 ms
59,520 KB |
testcase_02 | AC | 42 ms
52,608 KB |
testcase_03 | AC | 50 ms
60,928 KB |
testcase_04 | AC | 743 ms
76,160 KB |
testcase_05 | AC | 724 ms
76,288 KB |
testcase_06 | AC | 707 ms
76,288 KB |
testcase_07 | AC | 736 ms
76,160 KB |
testcase_08 | AC | 683 ms
76,288 KB |
testcase_09 | AC | 698 ms
76,288 KB |
testcase_10 | AC | 710 ms
76,160 KB |
testcase_11 | AC | 716 ms
76,544 KB |
testcase_12 | AC | 758 ms
76,288 KB |
testcase_13 | AC | 743 ms
76,288 KB |
testcase_14 | AC | 513 ms
76,288 KB |
testcase_15 | AC | 529 ms
76,416 KB |
testcase_16 | AC | 528 ms
76,416 KB |
testcase_17 | AC | 526 ms
76,288 KB |
testcase_18 | AC | 512 ms
76,416 KB |
testcase_19 | AC | 510 ms
76,288 KB |
testcase_20 | AC | 518 ms
76,160 KB |
testcase_21 | AC | 536 ms
76,288 KB |
testcase_22 | AC | 514 ms
76,160 KB |
testcase_23 | AC | 530 ms
76,160 KB |
testcase_24 | AC | 546 ms
76,288 KB |
testcase_25 | AC | 560 ms
76,288 KB |
testcase_26 | AC | 546 ms
76,288 KB |
testcase_27 | AC | 549 ms
76,416 KB |
testcase_28 | AC | 551 ms
76,416 KB |
testcase_29 | AC | 689 ms
76,160 KB |
testcase_30 | AC | 629 ms
76,160 KB |
testcase_31 | AC | 629 ms
76,288 KB |
testcase_32 | AC | 623 ms
76,288 KB |
testcase_33 | AC | 687 ms
76,288 KB |
testcase_34 | AC | 785 ms
76,160 KB |
testcase_35 | AC | 41 ms
52,352 KB |
testcase_36 | AC | 41 ms
52,224 KB |
testcase_37 | AC | 42 ms
52,608 KB |
testcase_38 | AC | 42 ms
52,224 KB |
testcase_39 | AC | 41 ms
52,608 KB |
testcase_40 | AC | 44 ms
52,480 KB |
testcase_41 | AC | 42 ms
52,352 KB |
testcase_42 | AC | 43 ms
52,352 KB |
testcase_43 | AC | 713 ms
76,288 KB |
ソースコード
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*26 col = [0]*26 if s[0] == "?" and s[1] == "?": for i in range(26): for j in range(26): if i == j: continue dp[i*26+j] = 1 col[j] += 1 elif s[0] == "?": j = ord(s[1])-97 for i in range(26): if i == j: continue dp[i*26+j] = 1 col[j] += 1 elif s[1] == "?": i = ord(s[0])-97 for j in range(26): if i == j: continue dp[i*26+j] = 1 col[j] += 1 else: i = ord(s[0])-97 j = ord(s[1])-97 dp[i*26+j] = 1 col[j] += 1 for c in s[2:]: a = ord(c)-97 ndp = [0]*26*26 ncl = [0]*26 for i in range(26): for j in range(26): if i == j: continue if c == "?" or j == a: val = (col[i]-dp[j*26+i])%md ndp[i*26+j] = val ncl[j] += val dp = ndp col = ncl ans = 0 for i in range(26): for j in range(26): ans += dp[i*26+j] ans %= md print(ans)