結果
| 問題 |
No.1740 Alone 'a'
|
| コンテスト | |
| ユーザー |
terasa
|
| 提出日時 | 2023-01-15 15:09:53 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 132 ms / 2,000 ms |
| コード長 | 1,094 bytes |
| コンパイル時間 | 374 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 80,256 KB |
| 最終ジャッジ日時 | 2024-12-28 07:45:24 |
| 合計ジャッジ時間 | 7,846 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
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])
terasa