結果
| 問題 | No.2019 Digits Filling for All Substrings |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-07-26 19:53:08 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 107 ms / 2,000 ms |
| コード長 | 454 bytes |
| 記録 | |
| コンパイル時間 | 201 ms |
| コンパイル使用メモリ | 84,864 KB |
| 実行使用メモリ | 81,792 KB |
| 最終ジャッジ日時 | 2026-03-30 22:26:11 |
| 合計ジャッジ時間 | 3,741 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
MOD = 998244353
n = int(input())
S = input()
dp = [0, 0, 0]
ans = 0
for s in S:
if s == "?":
lst = list(range(10))
else:
lst = [int(s)]
for x in lst:
ans += dp[-x % 3]
if x % 3 == 0:
ans += 1
ans %= MOD
ndp = [0] * 3
for x in lst:
ndp[x % 3] += 1
for i in range(3):
ndp[(i + x) % 3] += dp[i]
ndp[(i + x) % 3] %= MOD
dp = ndp
print(ans)