結果

問題 No.1646 Avoid Palindrome
ユーザー googol_S0googol_S0
提出日時 2021-08-13 22:11:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,990 ms / 3,000 ms
コード長 624 bytes
コンパイル時間 375 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 467,864 KB
最終ジャッジ日時 2024-04-26 03:00:49
合計ジャッジ時間 58,823 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
62,336 KB
testcase_01 AC 49 ms
62,720 KB
testcase_02 AC 45 ms
59,392 KB
testcase_03 AC 57 ms
62,848 KB
testcase_04 AC 1,750 ms
444,928 KB
testcase_05 AC 1,698 ms
445,056 KB
testcase_06 AC 1,658 ms
432,128 KB
testcase_07 AC 1,749 ms
444,672 KB
testcase_08 AC 1,704 ms
448,000 KB
testcase_09 AC 1,778 ms
430,120 KB
testcase_10 AC 1,815 ms
438,656 KB
testcase_11 AC 1,753 ms
428,652 KB
testcase_12 AC 1,775 ms
443,904 KB
testcase_13 AC 1,756 ms
448,128 KB
testcase_14 AC 1,761 ms
437,220 KB
testcase_15 AC 1,793 ms
444,808 KB
testcase_16 AC 1,741 ms
435,252 KB
testcase_17 AC 1,821 ms
450,680 KB
testcase_18 AC 1,784 ms
441,108 KB
testcase_19 AC 1,777 ms
439,528 KB
testcase_20 AC 1,790 ms
441,776 KB
testcase_21 AC 1,819 ms
450,724 KB
testcase_22 AC 1,758 ms
437,516 KB
testcase_23 AC 1,990 ms
452,236 KB
testcase_24 AC 1,885 ms
466,752 KB
testcase_25 AC 1,890 ms
466,644 KB
testcase_26 AC 1,886 ms
466,688 KB
testcase_27 AC 1,909 ms
466,684 KB
testcase_28 AC 1,923 ms
466,928 KB
testcase_29 AC 1,649 ms
467,256 KB
testcase_30 AC 1,632 ms
467,300 KB
testcase_31 AC 1,633 ms
467,404 KB
testcase_32 AC 1,629 ms
467,864 KB
testcase_33 AC 1,618 ms
467,364 KB
testcase_34 AC 1,842 ms
466,456 KB
testcase_35 AC 38 ms
52,748 KB
testcase_36 AC 39 ms
54,228 KB
testcase_37 AC 44 ms
61,232 KB
testcase_38 AC 43 ms
60,260 KB
testcase_39 AC 43 ms
59,884 KB
testcase_40 AC 42 ms
59,164 KB
testcase_41 AC 46 ms
61,312 KB
testcase_42 AC 45 ms
61,532 KB
testcase_43 AC 1,629 ms
467,256 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