結果

問題 No.1740 Alone 'a'
ユーザー mkawa2mkawa2
提出日時 2021-11-12 21:58:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 711 ms / 2,000 ms
コード長 1,306 bytes
コンパイル時間 468 ms
コンパイル使用メモリ 86,768 KB
実行使用メモリ 128,356 KB
最終ジャッジ日時 2023-08-17 01:21:57
合計ジャッジ時間 13,322 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,472 KB
testcase_01 AC 75 ms
71,240 KB
testcase_02 AC 77 ms
71,320 KB
testcase_03 AC 711 ms
128,276 KB
testcase_04 AC 680 ms
128,356 KB
testcase_05 AC 124 ms
79,008 KB
testcase_06 AC 120 ms
79,180 KB
testcase_07 AC 104 ms
77,012 KB
testcase_08 AC 75 ms
71,208 KB
testcase_09 AC 76 ms
71,216 KB
testcase_10 AC 76 ms
71,380 KB
testcase_11 AC 178 ms
86,540 KB
testcase_12 AC 467 ms
118,272 KB
testcase_13 AC 296 ms
115,852 KB
testcase_14 AC 523 ms
125,604 KB
testcase_15 AC 104 ms
77,148 KB
testcase_16 AC 421 ms
114,408 KB
testcase_17 AC 111 ms
77,756 KB
testcase_18 AC 168 ms
83,612 KB
testcase_19 AC 410 ms
118,256 KB
testcase_20 AC 269 ms
98,796 KB
testcase_21 AC 328 ms
106,468 KB
testcase_22 AC 373 ms
112,284 KB
testcase_23 AC 400 ms
112,420 KB
testcase_24 AC 289 ms
98,764 KB
testcase_25 AC 295 ms
98,884 KB
testcase_26 AC 357 ms
105,972 KB
testcase_27 AC 257 ms
107,860 KB
testcase_28 AC 292 ms
102,664 KB
testcase_29 AC 525 ms
125,580 KB
testcase_30 AC 255 ms
107,228 KB
testcase_31 AC 414 ms
113,612 KB
testcase_32 AC 333 ms
103,160 KB
testcase_33 AC 418 ms
113,256 KB
testcase_34 AC 139 ms
84,824 KB
testcase_35 AC 292 ms
101,620 KB
testcase_36 AC 284 ms
97,724 KB
testcase_37 AC 182 ms
85,064 KB
testcase_38 AC 236 ms
94,748 KB
testcase_39 AC 134 ms
80,164 KB
testcase_40 AC 188 ms
88,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = 18446744073709551615
inf = 4294967295
# md = 10**9+7
md = 998244353

n = II()
aa = [ord(c)-97 for c in SI()]

# dp[見た個数][aを使った][未満確定]
dp = [[[0]*2 for _ in range(2)] for _ in range(n+1)]
dp[0][0][0] = 1

def add(i, j, k, val):
    dp[i][j][k] = (dp[i][j][k]+val)%md

for i, a in enumerate(aa):
    for j in range(2):
        for k in range(2):
            pre = dp[i][j][k]
            if pre == 0: continue
            for c in range(26):
                nj = j
                nk = k
                if j and c == 0: continue
                if c == 0: nj = 1
                if k == 0 and c > a: continue
                if c < a: nk = 1
                add(i+1, nj, nk, pre)

print(dp[-1][1][1])
0