結果

問題 No.2019 Digits Filling for All Substrings
ユーザー okkuukenkenokkuukenken
提出日時 2022-07-22 22:46:14
言語 C++23(draft)
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 941 bytes
コンパイル時間 1,668 ms
コンパイル使用メモリ 130,216 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 11:19:02
合計ジャッジ時間 3,690 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 22 ms
4,376 KB
testcase_05 AC 16 ms
4,376 KB
testcase_06 AC 14 ms
4,380 KB
testcase_07 AC 11 ms
4,380 KB
testcase_08 AC 32 ms
4,376 KB
testcase_09 AC 45 ms
4,380 KB
testcase_10 AC 44 ms
4,376 KB
testcase_11 AC 44 ms
4,376 KB
testcase_12 AC 44 ms
4,380 KB
testcase_13 AC 44 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 35 ms
4,376 KB
testcase_25 AC 51 ms
4,384 KB
testcase_26 AC 24 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 42 ms
4,384 KB
testcase_30 AC 60 ms
4,380 KB
testcase_31 AC 58 ms
4,384 KB
testcase_32 AC 18 ms
4,376 KB
testcase_33 AC 45 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0