結果
問題 | No.1646 Avoid Palindrome |
ユーザー | brthyyjp |
提出日時 | 2022-01-20 15:51:35 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,354 ms / 3,000 ms |
コード長 | 1,981 bytes |
コンパイル時間 | 185 ms |
コンパイル使用メモリ | 82,132 KB |
実行使用メモリ | 78,872 KB |
最終ジャッジ日時 | 2024-11-23 20:57:20 |
合計ジャッジ時間 | 55,786 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
55,112 KB |
testcase_01 | AC | 50 ms
62,476 KB |
testcase_02 | AC | 41 ms
54,656 KB |
testcase_03 | AC | 53 ms
65,272 KB |
testcase_04 | AC | 1,229 ms
78,376 KB |
testcase_05 | AC | 1,221 ms
78,100 KB |
testcase_06 | AC | 1,307 ms
78,108 KB |
testcase_07 | AC | 1,225 ms
78,296 KB |
testcase_08 | AC | 1,410 ms
78,244 KB |
testcase_09 | AC | 1,209 ms
77,980 KB |
testcase_10 | AC | 1,331 ms
78,412 KB |
testcase_11 | AC | 1,202 ms
78,236 KB |
testcase_12 | AC | 1,274 ms
77,904 KB |
testcase_13 | AC | 1,231 ms
78,052 KB |
testcase_14 | AC | 2,162 ms
78,316 KB |
testcase_15 | AC | 2,201 ms
78,448 KB |
testcase_16 | AC | 2,136 ms
78,260 KB |
testcase_17 | AC | 2,259 ms
78,300 KB |
testcase_18 | AC | 2,191 ms
78,376 KB |
testcase_19 | AC | 2,175 ms
78,364 KB |
testcase_20 | AC | 2,202 ms
78,096 KB |
testcase_21 | AC | 2,236 ms
78,432 KB |
testcase_22 | AC | 2,164 ms
78,504 KB |
testcase_23 | AC | 2,255 ms
78,412 KB |
testcase_24 | AC | 2,343 ms
78,616 KB |
testcase_25 | AC | 2,342 ms
78,504 KB |
testcase_26 | AC | 2,354 ms
78,500 KB |
testcase_27 | AC | 2,336 ms
78,872 KB |
testcase_28 | AC | 2,325 ms
78,756 KB |
testcase_29 | AC | 863 ms
78,104 KB |
testcase_30 | AC | 868 ms
77,968 KB |
testcase_31 | AC | 872 ms
78,336 KB |
testcase_32 | AC | 925 ms
78,292 KB |
testcase_33 | AC | 882 ms
78,324 KB |
testcase_34 | AC | 2,309 ms
77,744 KB |
testcase_35 | AC | 41 ms
54,172 KB |
testcase_36 | AC | 44 ms
54,300 KB |
testcase_37 | AC | 42 ms
54,520 KB |
testcase_38 | AC | 40 ms
54,872 KB |
testcase_39 | AC | 40 ms
54,128 KB |
testcase_40 | AC | 40 ms
55,356 KB |
testcase_41 | AC | 41 ms
54,204 KB |
testcase_42 | AC | 41 ms
55,044 KB |
testcase_43 | AC | 833 ms
78,300 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 = 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()