結果
問題 |
No.1740 Alone 'a'
|
ユーザー |
|
提出日時 | 2021-11-12 22:05:40 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 194 ms / 2,000 ms |
コード長 | 967 bytes |
コンパイル時間 | 186 ms |
コンパイル使用メモリ | 81,972 KB |
実行使用メモリ | 77,660 KB |
最終ジャッジ日時 | 2024-11-25 18:43:49 |
合計ジャッジ時間 | 5,718 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
n = int(input()) S = input() L = [ord(s)-ord("a") for s in S] mod = 998244353 dp = [[0,0],[0,0]] dp[1][0] = 1 for l in L: ndp = [[0,0],[0,0]] for i in range(26): if i: ndp[0][0] += dp[0][0] ndp[0][0] %= mod ndp[0][1] += dp[0][1] ndp[0][1] %= mod else: ndp[0][1] += dp[0][0] ndp[0][1] %= mod if i < l: if i: ndp[0][0] += dp[1][0] ndp[0][0] %= mod ndp[0][1] += dp[1][1] ndp[0][1] %= mod else: ndp[0][1] += dp[1][0] ndp[0][1] %= mod elif i == l: if i: ndp[1][0] += dp[1][0] ndp[1][0] %= mod ndp[1][1] += dp[1][1] ndp[1][1] %= mod else: ndp[1][1] += dp[1][0] ndp[1][1] %= mod dp = ndp print(dp[0][1])