結果

問題 No.1740 Alone 'a'
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-11-12 22:21:44
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 696 ms / 2,000 ms
コード長 1,541 bytes
コンパイル時間 488 ms
コンパイル使用メモリ 87,224 KB
実行使用メモリ 88,424 KB
最終ジャッジ日時 2023-08-17 02:10:35
合計ジャッジ時間 15,889 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,568 KB
testcase_01 AC 72 ms
71,208 KB
testcase_02 AC 75 ms
71,284 KB
testcase_03 AC 696 ms
88,424 KB
testcase_04 AC 693 ms
88,304 KB
testcase_05 AC 135 ms
77,836 KB
testcase_06 AC 132 ms
77,880 KB
testcase_07 AC 114 ms
77,368 KB
testcase_08 AC 78 ms
76,436 KB
testcase_09 AC 73 ms
71,428 KB
testcase_10 AC 72 ms
71,276 KB
testcase_11 AC 214 ms
79,292 KB
testcase_12 AC 530 ms
86,360 KB
testcase_13 AC 524 ms
85,760 KB
testcase_14 AC 618 ms
87,696 KB
testcase_15 AC 116 ms
77,516 KB
testcase_16 AC 502 ms
85,396 KB
testcase_17 AC 119 ms
77,640 KB
testcase_18 AC 183 ms
78,628 KB
testcase_19 AC 539 ms
86,508 KB
testcase_20 AC 339 ms
81,836 KB
testcase_21 AC 419 ms
83,252 KB
testcase_22 AC 478 ms
84,936 KB
testcase_23 AC 468 ms
84,884 KB
testcase_24 AC 344 ms
81,812 KB
testcase_25 AC 342 ms
81,792 KB
testcase_26 AC 404 ms
83,116 KB
testcase_27 AC 429 ms
83,704 KB
testcase_28 AC 383 ms
82,480 KB
testcase_29 AC 626 ms
87,760 KB
testcase_30 AC 417 ms
83,852 KB
testcase_31 AC 498 ms
85,012 KB
testcase_32 AC 380 ms
82,576 KB
testcase_33 AC 475 ms
84,968 KB
testcase_34 AC 194 ms
79,168 KB
testcase_35 AC 363 ms
82,180 KB
testcase_36 AC 326 ms
81,332 KB
testcase_37 AC 196 ms
79,044 KB
testcase_38 AC 298 ms
81,064 KB
testcase_39 AC 148 ms
78,228 KB
testcase_40 AC 234 ms
80,092 KB
権限があれば一括ダウンロードができます

ソースコード

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
                if isa == 1 and c == 0:
                    continue

                linkb = 1
                if linka == 0:
                    linkb = 0
                if c != S[i]:
                    linkb = 0

                isb = 0
                if c == 0:
                    isb = 1
                if isa == 1:
                    isb = 1

                ndp[linkb][isb] += dp[linka][isa]
                
                """
                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