結果
問題 |
No.1740 Alone 'a'
|
ユーザー |
![]() |
提出日時 | 2021-11-14 22:04:09 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 334 ms / 2,000 ms |
コード長 | 1,179 bytes |
コンパイル時間 | 323 ms |
コンパイル使用メモリ | 81,792 KB |
実行使用メモリ | 90,368 KB |
最終ジャッジ日時 | 2024-11-30 07:37:55 |
合計ジャッジ時間 | 8,597 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#!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()