結果
| 問題 |
No.2019 Digits Filling for All Substrings
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-07-22 22:52:15 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 265 ms / 2,000 ms |
| コード長 | 608 bytes |
| コンパイル時間 | 341 ms |
| コンパイル使用メモリ | 82,440 KB |
| 実行使用メモリ | 76,676 KB |
| 最終ジャッジ日時 | 2024-07-04 07:25:36 |
| 合計ジャッジ時間 | 5,620 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
n = int(input())
S = input()
mod = 998244353
ans = 0
dp = [0]*3
for s in S:
ndp = [0]*3
for i in range(3):
if dp[i] == 0:
continue
for j in range(10):
if s == "?" or int(s) == j:
x = j%3
nx = (x+i)%3
if nx == 0:
ans += dp[i]
ans %= mod
ndp[nx] += dp[i]
ndp[nx] %= mod
for i in range(10):
if s == "?" or int(s) == i:
ndp[i%3] += 1
if i%3 == 0:
ans += 1
dp = ndp
print(ans%mod)