結果
| 問題 |
No.3242 Count 8 Included Numbers (Hard)
|
| コンテスト | |
| ユーザー |
timi
|
| 提出日時 | 2025-08-22 22:04:32 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 312 ms / 2,000 ms |
| コード長 | 945 bytes |
| コンパイル時間 | 185 ms |
| コンパイル使用メモリ | 82,244 KB |
| 実行使用メモリ | 78,184 KB |
| 最終ジャッジ日時 | 2025-08-22 22:04:39 |
| 合計ジャッジ時間 | 5,369 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 20 |
ソースコード
S=input()
mod=998244353
for i in range(len(S)):
s=int(S[i])
if i==0:
dp=[[0,0] for i in range(2)]
if s<=7:
dp[1][0]=s-1
dp[0][0]=1
elif s==8:
dp[1][0]=s-1
dp[0][1]=1
else:
dp[1][0]=s-2
dp[1][1]=1
dp[0][0]=1
else:
ndp=[[0,0] for i in range(2)]
for i in range(s+1):
if i!=s and i==8:
ndp[1][1]+=dp[0][0]
ndp[1][1]+=dp[0][1]
elif i==s and i==8:
ndp[0][1]+=dp[0][0]
ndp[0][1]+=dp[0][1]
elif i!=s and i!=8:
ndp[1][0]+=dp[0][0]
ndp[1][1]+=dp[0][1]
elif i==s and i!=8:
ndp[0][0]+=dp[0][0]
ndp[0][1]+=dp[0][1]
ndp[1][0]+=dp[1][0]*9
ndp[1][1]+=dp[1][0]
ndp[1][1]+=dp[1][1]*10
ndp[1][1]+=1
ndp[1][0]+=8
dp=ndp
dp[0][0]%=mod
dp[0][1]%=mod
dp[1][1]%=mod
dp[1][0]%=mod
ans=dp[0][1]+dp[1][1]
ans%=mod
print(ans)
timi