結果

問題 No.1740 Alone 'a'
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-11-12 22:16:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,151 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 87,300 KB
最終ジャッジ日時 2024-05-04 09:13:34
合計ジャッジ時間 10,843 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
52,224 KB
testcase_01 AC 32 ms
51,968 KB
testcase_02 AC 34 ms
52,608 KB
testcase_03 AC 503 ms
87,296 KB
testcase_04 AC 516 ms
87,300 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 36 ms
60,244 KB
testcase_09 AC 34 ms
52,132 KB
testcase_10 AC 34 ms
52,804 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 377 ms
84,364 KB
testcase_14 WA -
testcase_15 AC 73 ms
76,708 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 323 ms
82,916 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 324 ms
82,432 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 128 ms
78,080 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

dp[i][密着][aがあるか] = ?

"""

import sys
from sys import stdin


N = int(stdin.readline())

SI = list(stdin.readline()[:-1])

S = [ord(c)-ord("a") for c in SI]

#print (S)

mod = 998244353
dp = [[0,0],[0,0]]
dp[1][0] = 1

for i in range(N):

    ndp = [[0,0],[0,0]]

    for c in range(26):

        for linka in range(2):
            for isa in range(2):
                

                if linka == 1 and S[i] < c:
                    continue
                elif isa == 1 and c == 0:
                    continue

                if c == 0:
                    if S[i] == 0:
                        ndp[1][1] += dp[linka][isa]
                    else:
                        ndp[0][1] += dp[linka][isa]
                elif linka == 1:
                    if S[i] == c:
                        ndp[1][isa] += dp[linka][isa]
                    else:
                        ndp[0][isa] += dp[linka][isa]
                else:
                    ndp[linka][isa] += dp[linka][isa]

    for x in range(2):
        for y in range(2):
            ndp[x][y] %= mod
    dp = ndp
    #print (dp)

#print (dp)
print (dp[0][1] % mod)
    
0