結果
| 問題 |
No.2019 Digits Filling for All Substrings
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-07-22 22:46:14 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 59 ms / 2,000 ms |
| コード長 | 941 bytes |
| コンパイル時間 | 1,276 ms |
| コンパイル使用メモリ | 132,208 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-04 07:17:49 |
| 合計ジャッジ時間 | 2,862 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<random>
using namespace std;
typedef long long ll;
const int mod=998244353;
ll mypow(int x,ll n){
if(n==0)
return 1;
if(n%2==1)
return mypow(x,n-1)*x%mod;
ll res=mypow(x,n/2);
return res*res%mod;
}
ll inv(int x){
return mypow(x,mod-2);
}
int main(){
int n;
string s;
cin>>n>>s;
int ans1=0,tmp1=0,tmp2=1;
for(auto x:s){
if(x=='?')
tmp2=tmp2*10ll%mod;
(tmp1+=tmp2)%=mod;
}
for(auto x:s){
(ans1+=tmp1)%=mod;
if(x=='?')
tmp1=tmp1*inv(10)%mod;
(tmp1+=mod-1)%=mod;
}
ll tmp3=(n+1ll)*n/2;
(ans1+=mod-tmp3%mod)%=mod;
ans1=ans1*inv(3)%mod;
int ans2=0,cnt[3]={1,0,0},sum=0;
for(auto x:s){
(sum+=x)%=3;
(ans2+=cnt[sum])%=mod;
cnt[sum]++;
}
cout<<(ans1+ans2)%mod<<endl;
}