結果

問題 No.1646 Avoid Palindrome
ユーザー googol_S0googol_S0
提出日時 2021-08-13 22:11:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,021 ms / 3,000 ms
コード長 624 bytes
コンパイル時間 444 ms
コンパイル使用メモリ 87,220 KB
実行使用メモリ 468,240 KB
最終ジャッジ日時 2023-08-08 09:47:48
合計ジャッジ時間 59,876 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
76,176 KB
testcase_01 AC 85 ms
76,560 KB
testcase_02 AC 79 ms
75,924 KB
testcase_03 AC 85 ms
76,552 KB
testcase_04 AC 1,770 ms
442,584 KB
testcase_05 AC 1,758 ms
445,592 KB
testcase_06 AC 1,679 ms
433,280 KB
testcase_07 AC 1,774 ms
445,568 KB
testcase_08 AC 1,724 ms
449,008 KB
testcase_09 AC 1,732 ms
431,012 KB
testcase_10 AC 1,696 ms
439,372 KB
testcase_11 AC 1,649 ms
429,256 KB
testcase_12 AC 1,758 ms
444,656 KB
testcase_13 AC 1,731 ms
449,288 KB
testcase_14 AC 1,758 ms
438,168 KB
testcase_15 AC 1,794 ms
445,440 KB
testcase_16 AC 1,767 ms
435,632 KB
testcase_17 AC 1,815 ms
451,816 KB
testcase_18 AC 1,775 ms
441,400 KB
testcase_19 AC 1,770 ms
439,776 KB
testcase_20 AC 1,792 ms
442,444 KB
testcase_21 AC 1,817 ms
451,400 KB
testcase_22 AC 1,763 ms
438,240 KB
testcase_23 AC 2,021 ms
452,836 KB
testcase_24 AC 1,905 ms
466,344 KB
testcase_25 AC 1,895 ms
467,316 KB
testcase_26 AC 1,892 ms
467,668 KB
testcase_27 AC 1,904 ms
467,812 KB
testcase_28 AC 1,899 ms
467,336 KB
testcase_29 AC 1,621 ms
467,944 KB
testcase_30 AC 1,626 ms
468,240 KB
testcase_31 AC 1,611 ms
467,968 KB
testcase_32 AC 1,637 ms
467,944 KB
testcase_33 AC 1,629 ms
467,944 KB
testcase_34 AC 1,832 ms
467,120 KB
testcase_35 AC 77 ms
71,052 KB
testcase_36 AC 76 ms
71,460 KB
testcase_37 AC 83 ms
76,100 KB
testcase_38 AC 77 ms
76,012 KB
testcase_39 AC 79 ms
76,068 KB
testcase_40 AC 80 ms
75,816 KB
testcase_41 AC 84 ms
76,104 KB
testcase_42 AC 84 ms
75,960 KB
testcase_43 AC 1,628 ms
467,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
S=list(input())
for i in range(N):
  if S[i]=='?':
    S[i]=-1
  else:
    S[i]=ord(S[i])-ord('a')
DP=[[[0]*27 for j in range(27)] for i in range(N+1)]
DP[0][26][26]=1
mod=998244353
for i in range(N):
  cx=[0]*27
  cy=[0]*27
  for j in range(27):
    for k in range(27):
      cx[j]=(cx[j]+DP[i][j][k])%mod
      cy[k]=(cy[k]+DP[i][j][k])%mod
  a=S[i]
  for j in range(26):
    for k in range(27):
      if a==j:
        if j!=k:
          DP[i+1][j][k]=(cx[k]-DP[i][k][a])%mod
      if a==-1:
        if j!=k:
          DP[i+1][j][k]=(cx[k]-DP[i][k][j])%mod
print(sum([sum(DP[N][i]) for i in range(27)])%mod)
0