結果
| 問題 |
No.2019 Digits Filling for All Substrings
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2022-07-22 23:36:15 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 26 ms / 2,000 ms |
| コード長 | 724 bytes |
| コンパイル時間 | 2,430 ms |
| コンパイル使用メモリ | 194,144 KB |
| 最終ジャッジ日時 | 2025-01-30 13:07:31 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
ll dp[200200][3];
const int MOD=998244353;
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
string s;
cin>>n>>s;
rep(i,n){
if(s[i]!='?'){
int x=s[i]-'0';
rep(j,3) dp[i+1][(j*10+x)%3]=(dp[i+1][(j*10+x)%3]+dp[i][j])%MOD;
dp[i+1][x%3]=(dp[i+1][x%3]+1)%MOD;
}
else{
rep(k,10){
rep(j,3) dp[i+1][(j*10+k)%3]=(dp[i+1][(j*10+k)%3]+dp[i][j])%MOD;
dp[i+1][k%3]=(dp[i+1][k%3]+1)%MOD;
}
}
}
ll ans=0;
for(int i=1;i<=n;i++) ans=(ans+dp[i][0])%MOD;
cout<<ans<<endl;
return 0;
}
umezo