結果
| 問題 |
No.2019 Digits Filling for All Substrings
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-08-05 14:38:21 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 279 ms / 2,000 ms |
| コード長 | 587 bytes |
| コンパイル時間 | 263 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 76,800 KB |
| 最終ジャッジ日時 | 2024-09-15 10:21:46 |
| 合計ジャッジ時間 | 6,358 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
import sys
input = sys.stdin.readline
N = int(input())
S = input()[:-1]
dp = [[0]*3 for _ in range(2)]
dp[0][0] = 1
ans = 0
MOD = 998244353
for Si in S:
ndp = [[0]*3 for _ in range(2)]
for i in range(3):
ndp[0][i] = dp[0][i]
if Si=='?':
nums = list(range(10))
else:
nums = [int(Si)]
for i in range(2):
for j in range(3):
for num in nums:
nj = (j+num)%3
ndp[1][nj] += dp[i][j]
ndp[1][nj] %= MOD
dp = ndp
ans += dp[1][0]
ans %= MOD
print(ans)