結果
問題 | No.1646 Avoid Palindrome |
ユーザー | brthyyjp |
提出日時 | 2022-01-20 15:48:19 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,920 bytes |
コンパイル時間 | 330 ms |
コンパイル使用メモリ | 82,688 KB |
実行使用メモリ | 79,044 KB |
最終ジャッジ日時 | 2024-11-23 20:51:42 |
合計ジャッジ時間 | 55,557 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
54,272 KB |
testcase_01 | AC | 47 ms
61,056 KB |
testcase_02 | AC | 45 ms
60,928 KB |
testcase_03 | AC | 52 ms
64,768 KB |
testcase_04 | AC | 1,229 ms
78,080 KB |
testcase_05 | WA | - |
testcase_06 | AC | 1,305 ms
78,112 KB |
testcase_07 | AC | 1,220 ms
77,952 KB |
testcase_08 | WA | - |
testcase_09 | AC | 1,197 ms
78,176 KB |
testcase_10 | AC | 1,322 ms
78,472 KB |
testcase_11 | AC | 1,205 ms
77,824 KB |
testcase_12 | AC | 1,262 ms
78,232 KB |
testcase_13 | WA | - |
testcase_14 | AC | 2,145 ms
78,464 KB |
testcase_15 | AC | 2,196 ms
78,592 KB |
testcase_16 | AC | 2,143 ms
78,404 KB |
testcase_17 | AC | 2,298 ms
78,588 KB |
testcase_18 | AC | 2,163 ms
78,336 KB |
testcase_19 | AC | 2,159 ms
79,044 KB |
testcase_20 | AC | 2,213 ms
78,336 KB |
testcase_21 | AC | 2,243 ms
78,208 KB |
testcase_22 | AC | 2,169 ms
78,336 KB |
testcase_23 | AC | 2,267 ms
78,464 KB |
testcase_24 | AC | 2,340 ms
78,796 KB |
testcase_25 | AC | 2,316 ms
78,592 KB |
testcase_26 | AC | 2,315 ms
78,404 KB |
testcase_27 | AC | 2,308 ms
78,520 KB |
testcase_28 | AC | 2,318 ms
78,640 KB |
testcase_29 | AC | 882 ms
78,208 KB |
testcase_30 | AC | 868 ms
78,336 KB |
testcase_31 | AC | 867 ms
78,208 KB |
testcase_32 | AC | 870 ms
78,336 KB |
testcase_33 | AC | 829 ms
78,336 KB |
testcase_34 | AC | 2,299 ms
77,696 KB |
testcase_35 | AC | 41 ms
54,016 KB |
testcase_36 | AC | 40 ms
54,272 KB |
testcase_37 | AC | 41 ms
54,016 KB |
testcase_38 | AC | 41 ms
54,144 KB |
testcase_39 | WA | - |
testcase_40 | AC | 40 ms
53,888 KB |
testcase_41 | AC | 41 ms
54,144 KB |
testcase_42 | AC | 41 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()