結果

問題 No.1740 Alone 'a'
ユーザー dn6049949dn6049949
提出日時 2021-11-14 22:04:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 367 ms / 2,000 ms
コード長 1,179 bytes
コンパイル時間 2,218 ms
コンパイル使用メモリ 87,028 KB
実行使用メモリ 91,488 KB
最終ジャッジ日時 2023-08-20 06:55:05
合計ジャッジ時間 11,855 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
71,484 KB
testcase_01 AC 90 ms
71,560 KB
testcase_02 AC 91 ms
71,444 KB
testcase_03 AC 367 ms
91,292 KB
testcase_04 AC 361 ms
91,424 KB
testcase_05 AC 121 ms
77,856 KB
testcase_06 AC 124 ms
77,704 KB
testcase_07 AC 114 ms
77,380 KB
testcase_08 AC 89 ms
71,660 KB
testcase_09 AC 88 ms
71,580 KB
testcase_10 AC 93 ms
71,740 KB
testcase_11 AC 162 ms
79,364 KB
testcase_12 AC 310 ms
87,844 KB
testcase_13 AC 223 ms
87,880 KB
testcase_14 AC 350 ms
91,488 KB
testcase_15 AC 113 ms
77,664 KB
testcase_16 AC 295 ms
87,356 KB
testcase_17 AC 116 ms
77,876 KB
testcase_18 AC 145 ms
78,484 KB
testcase_19 AC 312 ms
87,568 KB
testcase_20 AC 227 ms
83,232 KB
testcase_21 AC 262 ms
84,756 KB
testcase_22 AC 288 ms
87,356 KB
testcase_23 AC 283 ms
87,424 KB
testcase_24 AC 229 ms
82,980 KB
testcase_25 AC 222 ms
83,096 KB
testcase_26 AC 250 ms
85,084 KB
testcase_27 AC 202 ms
86,028 KB
testcase_28 AC 237 ms
84,000 KB
testcase_29 AC 349 ms
91,220 KB
testcase_30 AC 196 ms
85,836 KB
testcase_31 AC 292 ms
87,020 KB
testcase_32 AC 237 ms
84,288 KB
testcase_33 AC 287 ms
87,216 KB
testcase_34 AC 134 ms
78,800 KB
testcase_35 AC 233 ms
83,700 KB
testcase_36 AC 260 ms
82,544 KB
testcase_37 AC 155 ms
78,576 KB
testcase_38 AC 197 ms
81,908 KB
testcase_39 AC 132 ms
77,936 KB
testcase_40 AC 164 ms
79,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def IR(n):
    return [I() for _ in range(n)]
def LIR(n):
    return [LI() for _ in range(n)]

sys.setrecursionlimit(1000000)
mod = 998244353

def main():
    n = I()
    s = list(map(lambda x:ord(x)-ord("a"),input()))
    dp = [[0]*2 for _ in range(2)]
    dp[0][0] = 1
    for i in s:
        ndp = [[0]*2 for _ in range(2)]
        for j in range(2):
            x = 26 if j else i+1
            for k in range(2):
                dpjk = dp[j][k]
                if not dpjk:
                    continue
                for l in range(x):
                    nk = k+(l==0)
                    if nk > 1:
                        continue
                    nj = j|(l<i)
                    ndp[nj][nk] += dpjk
                    if ndp[nj][nk] >= mod:
                        ndp[nj][nk] -= mod
        dp = ndp
    print(dp[1][1])
    return


if __name__ == "__main__":
    main()
0