結果

問題 No.1740 Alone 'a'
ユーザー terasaterasa
提出日時 2023-01-15 15:09:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 198 ms / 2,000 ms
コード長 1,094 bytes
コンパイル時間 419 ms
コンパイル使用メモリ 86,908 KB
実行使用メモリ 83,892 KB
最終ジャッジ日時 2023-08-27 22:39:16
合計ジャッジ時間 10,982 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 164 ms
79,924 KB
testcase_01 AC 159 ms
80,000 KB
testcase_02 AC 159 ms
80,004 KB
testcase_03 AC 198 ms
83,892 KB
testcase_04 AC 194 ms
83,724 KB
testcase_05 AC 172 ms
82,160 KB
testcase_06 AC 168 ms
82,372 KB
testcase_07 AC 168 ms
81,684 KB
testcase_08 AC 159 ms
80,060 KB
testcase_09 AC 160 ms
79,668 KB
testcase_10 AC 159 ms
79,912 KB
testcase_11 AC 180 ms
82,372 KB
testcase_12 AC 193 ms
83,644 KB
testcase_13 AC 189 ms
83,348 KB
testcase_14 AC 195 ms
83,572 KB
testcase_15 AC 169 ms
82,524 KB
testcase_16 AC 185 ms
83,208 KB
testcase_17 AC 169 ms
82,396 KB
testcase_18 AC 174 ms
82,752 KB
testcase_19 AC 187 ms
83,408 KB
testcase_20 AC 182 ms
82,676 KB
testcase_21 AC 186 ms
83,000 KB
testcase_22 AC 186 ms
83,420 KB
testcase_23 AC 192 ms
83,416 KB
testcase_24 AC 182 ms
82,616 KB
testcase_25 AC 181 ms
82,656 KB
testcase_26 AC 183 ms
82,612 KB
testcase_27 AC 186 ms
83,040 KB
testcase_28 AC 182 ms
83,108 KB
testcase_29 AC 189 ms
83,736 KB
testcase_30 AC 182 ms
83,008 KB
testcase_31 AC 185 ms
83,260 KB
testcase_32 AC 181 ms
82,968 KB
testcase_33 AC 185 ms
83,252 KB
testcase_34 AC 174 ms
82,552 KB
testcase_35 AC 184 ms
82,524 KB
testcase_36 AC 177 ms
82,788 KB
testcase_37 AC 172 ms
82,556 KB
testcase_38 AC 178 ms
82,268 KB
testcase_39 AC 170 ms
82,404 KB
testcase_40 AC 173 ms
82,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from typing import List, Tuple, Callable, TypeVar, Optional
import sys
import itertools
import heapq
import bisect
import math
from collections import deque, defaultdict
from functools import lru_cache, cmp_to_key

input = sys.stdin.readline

if __file__ != 'prog.py':
    sys.setrecursionlimit(10 ** 6)


def readints(): return map(int, input().split())
def readlist(): return list(readints())
def readstr(): return input()[:-1]
def readlist1(): return list(map(lambda x: int(x) - 1, input().split()))


N = int(input())
A = [ord(c) - ord('a') for c in readstr()]
mod = 998244353

dp = [[0, 0], [0, 0]]
dp[0][0] = 1
for i in range(N):
    ndp = [[0, 0], [0, 0]]
    ndp[1][1] += dp[1][1] * 25
    ndp[1][1] += dp[0][1]
    ndp[0][1] += dp[0][1] * 25

    if A[i] == 0:
        ndp[1][0] += dp[0][0]
    else:
        ndp[1][1] += dp[1][0] * (A[i] - 1)
        ndp[1][0] += dp[1][0]
        ndp[1][1] += dp[0][0]
        ndp[0][1] += dp[0][0] * (A[i] - 1)
        ndp[0][0] += dp[0][0]
    for j in range(2):
        for k in range(2):
            ndp[j][k] %= mod
    dp = ndp
print(dp[1][1])
0