結果
問題 | No.1646 Avoid Palindrome |
ユーザー | brthyyjp |
提出日時 | 2022-01-20 15:51:35 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,463 ms / 3,000 ms |
コード長 | 1,981 bytes |
コンパイル時間 | 450 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 79,136 KB |
最終ジャッジ日時 | 2024-05-03 01:04:13 |
合計ジャッジ時間 | 59,464 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
54,656 KB |
testcase_01 | AC | 48 ms
61,312 KB |
testcase_02 | AC | 43 ms
54,400 KB |
testcase_03 | AC | 56 ms
64,768 KB |
testcase_04 | AC | 1,281 ms
78,080 KB |
testcase_05 | AC | 1,269 ms
77,876 KB |
testcase_06 | AC | 1,355 ms
77,952 KB |
testcase_07 | AC | 1,263 ms
78,208 KB |
testcase_08 | AC | 1,507 ms
78,372 KB |
testcase_09 | AC | 1,293 ms
78,180 KB |
testcase_10 | AC | 1,372 ms
78,336 KB |
testcase_11 | AC | 1,299 ms
77,980 KB |
testcase_12 | AC | 1,344 ms
78,080 KB |
testcase_13 | AC | 1,282 ms
78,208 KB |
testcase_14 | AC | 2,319 ms
78,584 KB |
testcase_15 | AC | 2,315 ms
78,336 KB |
testcase_16 | AC | 2,253 ms
78,464 KB |
testcase_17 | AC | 2,411 ms
78,464 KB |
testcase_18 | AC | 2,293 ms
78,508 KB |
testcase_19 | AC | 2,328 ms
78,580 KB |
testcase_20 | AC | 2,324 ms
78,272 KB |
testcase_21 | AC | 2,339 ms
78,592 KB |
testcase_22 | AC | 2,265 ms
78,464 KB |
testcase_23 | AC | 2,349 ms
78,592 KB |
testcase_24 | AC | 2,428 ms
78,452 KB |
testcase_25 | AC | 2,428 ms
78,720 KB |
testcase_26 | AC | 2,454 ms
78,592 KB |
testcase_27 | AC | 2,453 ms
78,464 KB |
testcase_28 | AC | 2,463 ms
79,136 KB |
testcase_29 | AC | 922 ms
78,208 KB |
testcase_30 | AC | 925 ms
78,148 KB |
testcase_31 | AC | 926 ms
78,080 KB |
testcase_32 | AC | 925 ms
78,336 KB |
testcase_33 | AC | 901 ms
77,952 KB |
testcase_34 | AC | 2,449 ms
77,824 KB |
testcase_35 | AC | 41 ms
53,888 KB |
testcase_36 | AC | 41 ms
53,632 KB |
testcase_37 | AC | 43 ms
53,760 KB |
testcase_38 | AC | 41 ms
53,760 KB |
testcase_39 | AC | 42 ms
53,888 KB |
testcase_40 | AC | 43 ms
53,632 KB |
testcase_41 | AC | 43 ms
54,144 KB |
testcase_42 | AC | 44 ms
54,376 KB |
testcase_43 | AC | 883 ms
78,080 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()