結果
問題 | No.1646 Avoid Palindrome |
ユーザー | brthyyjp |
提出日時 | 2022-01-20 15:53:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 777 ms / 3,000 ms |
コード長 | 1,978 bytes |
コンパイル時間 | 137 ms |
コンパイル使用メモリ | 82,444 KB |
実行使用メモリ | 78,188 KB |
最終ジャッジ日時 | 2024-05-03 01:05:31 |
合計ジャッジ時間 | 22,679 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
54,936 KB |
testcase_01 | AC | 53 ms
62,224 KB |
testcase_02 | AC | 36 ms
55,528 KB |
testcase_03 | AC | 45 ms
63,596 KB |
testcase_04 | AC | 530 ms
77,124 KB |
testcase_05 | AC | 531 ms
76,940 KB |
testcase_06 | AC | 625 ms
77,396 KB |
testcase_07 | AC | 528 ms
77,092 KB |
testcase_08 | AC | 659 ms
77,460 KB |
testcase_09 | AC | 506 ms
76,932 KB |
testcase_10 | AC | 651 ms
77,200 KB |
testcase_11 | AC | 501 ms
77,236 KB |
testcase_12 | AC | 521 ms
76,872 KB |
testcase_13 | AC | 537 ms
77,052 KB |
testcase_14 | AC | 711 ms
77,240 KB |
testcase_15 | AC | 725 ms
77,024 KB |
testcase_16 | AC | 699 ms
77,264 KB |
testcase_17 | AC | 732 ms
77,240 KB |
testcase_18 | AC | 716 ms
77,072 KB |
testcase_19 | AC | 717 ms
77,256 KB |
testcase_20 | AC | 714 ms
76,964 KB |
testcase_21 | AC | 733 ms
77,240 KB |
testcase_22 | AC | 706 ms
77,096 KB |
testcase_23 | AC | 747 ms
77,104 KB |
testcase_24 | AC | 769 ms
77,600 KB |
testcase_25 | AC | 777 ms
76,892 KB |
testcase_26 | AC | 757 ms
77,124 KB |
testcase_27 | AC | 751 ms
77,104 KB |
testcase_28 | AC | 754 ms
76,976 KB |
testcase_29 | AC | 603 ms
77,240 KB |
testcase_30 | AC | 615 ms
78,188 KB |
testcase_31 | AC | 602 ms
77,336 KB |
testcase_32 | AC | 612 ms
77,772 KB |
testcase_33 | AC | 574 ms
77,416 KB |
testcase_34 | AC | 768 ms
76,620 KB |
testcase_35 | AC | 36 ms
54,612 KB |
testcase_36 | AC | 36 ms
54,844 KB |
testcase_37 | AC | 36 ms
54,056 KB |
testcase_38 | AC | 35 ms
54,716 KB |
testcase_39 | AC | 36 ms
54,612 KB |
testcase_40 | AC | 35 ms
54,592 KB |
testcase_41 | AC | 36 ms
55,912 KB |
testcase_42 | AC | 36 ms
54,360 KB |
testcase_43 | AC | 579 ms
77,672 KB |
ソースコード
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[1])-ord('a') if c0 == c1: print(0) exit() 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 = [0]*26 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()