結果
| 問題 |
No.1740 Alone 'a'
|
| コンテスト | |
| ユーザー |
👑 Kazun
|
| 提出日時 | 2021-10-17 02:20:23 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 78 ms / 2,000 ms |
| コード長 | 725 bytes |
| コンパイル時間 | 267 ms |
| コンパイル使用メモリ | 82,236 KB |
| 実行使用メモリ | 89,848 KB |
| 最終ジャッジ日時 | 2024-11-25 10:59:53 |
| 合計ジャッジ時間 | 3,973 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
N=int(input())
S=list(map(lambda x:ord(x)-ord("a"),input())) # a->0, b->1, ..., y->24, z->25 に変換
DP=[[1,0],[0,0]] # DP[mode][flag]:=辞書式未満が確定して (いて/おらず), 'a' を使ってい (る/ない) 文字列の個数
Mod=998244353
for x in S:
E=DP
DP=[[0,0],[0,0]]
# False -> False
if x==0:
DP[0][1]=E[0][0]
else:
DP[0][0]=E[0][0]
DP[0][1]=E[0][1]
# False -> True
if x!=0:
DP[1][1]=E[0][0]
DP[1][0]+=E[0][0]*(x-1)
DP[1][1]+=E[0][1]*(x-1)
# True -> True
DP[1][0]+=E[1][0]*25
DP[1][1]+=E[1][0]
DP[1][1]+=E[1][1]*25
DP[0][0]%=Mod
DP[0][1]%=Mod
DP[1][0]%=Mod
DP[1][1]%=Mod
print(DP[1][1])
Kazun