QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#720004#9614. 分治xukai100 ✓1422ms8424kbC++143.4kb2024-11-07 10:13:582024-11-07 10:13:59

Judging History

你现在查看的是最新测评结果

  • [2024-11-07 10:13:59]
  • 评测
  • 测评结果:100
  • 用时:1422ms
  • 内存:8424kb
  • [2024-11-07 10:13:58]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=200010,mod=998244353;
inline void Add(int&x,int y){
	x=(x+y>=mod?x+y-mod:x+y);
}
inline void Sub(int&x,int y){
	x=(x-y<0?x-y+mod:x-y);
}
int qmi(int a,int b){
	int r=1;
	for(;b;b>>=1){
		if(b&1)r=(ll)r*a%mod;
		a=(ll)a*a%mod;
	}
	return r;
}
int jc[N],ny[N];
void prepare_C(int nn){
	jc[0]=1;
	for(int i=1;i<=nn;i++)jc[i]=(ll)jc[i-1]*i%mod;
	ny[nn]=qmi(jc[nn],mod-2);
	for(int i=nn;i;i--)ny[i-1]=(ll)ny[i]*i%mod;
}
int C(int x,int y){
	if(x<y||y<0)return 0;
	return (ll)jc[x]*ny[x-y]%mod*ny[y]%mod;
}
char s[N];int l,mi2[N];

int Solve1(){
	int ans=0;
	for(int i=1;i<=l-1;i++){
		for(int j=1;(i+1)*j<=l-1;j++){
			if(j&1){
				Add(ans,(ll)C(l-1-(i+1)*j+j+1-1,j)*mi2[l-1-(i+1)*j]%mod);
			}
			else{
				Sub(ans,(ll)C(l-1-(i+1)*j+j+1-1,j)*mi2[l-1-(i+1)*j]%mod);
			}
		}
		for(int j=1;i+(i+1)*(j-1)<=l-1;j++){
			if(j&1){
				Add(ans,(ll)C(l-1-i-(i+1)*(j-1)+j-1,j-1)*mi2[l-1-i-(i+1)*(j-1)]%mod);
			}
			else{
				Sub(ans,(ll)C(l-1-i-(i+1)*(j-1)+j-1,j-1)*mi2[l-1-i-(i+1)*(j-1)]%mod);
			}
		}
	}
	return ans;
}

const int B=500;
int f[N];
int Solve2(){
	int ans=0,mx=1,now=1,cur=0;
	
	vector<pair<int,int>>q,q1;
	for(int i=1;i<l;i++){
		cur=max(cur,i);
		while(cur<l&&s[cur]=='0')cur++;
		if(cur==l)break;
		
		if(s[i-1]=='1'){
			int s=cur-i+1,t=max(mx,s),n=l-1-i+1,res=0;
			if(i==1)t=s+1;
			
			Add(res,(ll)mi2[n-s]*t%mod);
			q.push_back({n-s,t+1});
			if(i==1){
				for(int j=t+1;j<=n+1;j++){
					for(int k=1;j-1+(j+1)*(k-1)<=n;k++){
						if(k&1){
							Add(res,(ll)C(n-(j-1)-(j+1)*(k-1)+k-1,k-1)*mi2[n-(j-1)-(j+1)*(k-1)]%mod);
						}
						else{
							Sub(res,(ll)C(n-(j-1)-(j+1)*(k-1)+k-1,k-1)*mi2[n-(j-1)-(j+1)*(k-1)]%mod);
						}
					}
				}
			}
			else{
				q1.push_back({n,t+1});
			}
			Add(ans,res);
		}
		if(s[i]=='1'){
			now=0;
		}
		else{
			now++;
			mx=max(mx,now);
		}
	}
	for(int j=1;j<=B;j++){
		int res=0;
		memset(f,0,sizeof f);
		for(int i=j+1;i<=l;i++){
			f[i]=f[i-1];Add(f[i],f[i]);
			Sub(f[i],f[i-1-j]);Add(f[i],mi2[i-j-1]);
		}
		for(auto pr:q){
			int n=pr.first,t=pr.second;
			if(t<=j){
				Add(res,f[n]);
			}
		}
		for(auto pr:q1){
			int n=pr.first,t=pr.second;
			if(t<=j&&n>=j){
				int val=0;Sub(val,f[n-j]);
				Add(val,mi2[n-(j+1)+1]);
				Add(res,val);
			}
		}
		Add(ans,res);
	}
	for(int k=1;k<=B;k++){
		int res=0;
		memset(f,0,sizeof f);
		for(int i=k;i<=l;i++){
			f[i]=f[i-k];
			Add(f[i],(ll)C(i,k)*mi2[i-k]%mod);
		}
		for(auto pr:q){
			int n=pr.first,t=max(pr.second,B+1);
			if(n-t*k<0)continue;
			Add(res,f[n-t*k]);
		}
		if(k&1){
			Add(ans,res);
		}
		else{
			Sub(ans,res);
		}
	}
	for(int k=1;k<=B;k++){
		int res=0;
		memset(f,0,sizeof f);
		for(int i=k-1;i<=l;i++){
			if(i>=k)f[i]=f[i-k];
			Add(f[i],(ll)C(i,k-1)*mi2[i-k+1]%mod);
		}
		for(auto pr:q1){
			int n=pr.first,t=max(pr.second,B+1);
			if(n-t*k<0)continue;
			Add(res,f[n-t*k]);
		}
		if(k&1){
			Add(ans,res);
		}
		else{
			Sub(ans,res);
		}
	}
	return ans;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	cin>>s;l=strlen(s);
	
	prepare_C(l);
	mi2[0]=1;
	for(int i=1;i<=l;i++)mi2[i]=(mi2[i-1]+mi2[i-1])%mod;
	
	int v=0;
	Add(v,Solve1());
	Add(v,Solve2());
	
	int n=0;
	for(int i=0;i<l;i++)n=(n+n+s[i]-'0')%mod;
	Add(v,n);
	
	cout<<v;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 18ms
memory: 4540kb

input:

110

output:

15

result:

ok 1 number(s): "15"

Test #2:

score: 10
Accepted
time: 19ms
memory: 6448kb

input:

101

output:

12

result:

ok 1 number(s): "12"

Subtask #2:

score: 10
Accepted

Dependency #1:

100%
Accepted

Test #3:

score: 10
Accepted
time: 18ms
memory: 5972kb

input:

111110

output:

198

result:

ok 1 number(s): "198"

Test #4:

score: 10
Accepted
time: 19ms
memory: 6640kb

input:

1001001

output:

253

result:

ok 1 number(s): "253"

Subtask #3:

score: 20
Accepted

Dependency #2:

100%
Accepted

Test #5:

score: 20
Accepted
time: 18ms
memory: 6444kb

input:

10100011000100111

output:

386882

result:

ok 1 number(s): "386882"

Test #6:

score: 20
Accepted
time: 19ms
memory: 6108kb

input:

111010011111010110

output:

1107742

result:

ok 1 number(s): "1107742"

Subtask #4:

score: 5
Accepted

Test #7:

score: 5
Accepted
time: 15ms
memory: 6376kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

output:

412796008

result:

ok 1 number(s): "412796008"

Test #8:

score: 5
Accepted
time: 18ms
memory: 4328kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

output:

818656648

result:

ok 1 number(s): "818656648"

Subtask #5:

score: 5
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #9:

score: 5
Accepted
time: 19ms
memory: 6076kb

input:

10000000100000010010011110111101101110000000000001100000011000111111010011010101010000101001110110010001100110000110111101000101001111101111001010001001011101011111010000100010111100110000001101111

output:

703266161

result:

ok 1 number(s): "703266161"

Test #10:

score: 5
Accepted
time: 19ms
memory: 6428kb

input:

110100000100001000101000010010101000110111101010110000101001001100100111000011100101110110010000001111010011101001111110110010001110011101001111010101100100010011101010101111111111010110001100100110

output:

330527406

result:

ok 1 number(s): "330527406"

Subtask #6:

score: 5
Accepted

Dependency #4:

100%
Accepted

Test #11:

score: 5
Accepted
time: 23ms
memory: 4408kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

340672883

result:

ok 1 number(s): "340672883"

Test #12:

score: 5
Accepted
time: 27ms
memory: 4440kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

555946758

result:

ok 1 number(s): "555946758"

Subtask #7:

score: 10
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Test #13:

score: 10
Accepted
time: 30ms
memory: 4444kb

input:

110011100110101000000110101010111111001101101011010110100100110010111110110110000111011001110000101111110111011111000110001011011011101100001100100011010010111111010110010000101001001000100001100100000001000111110100000101001011100001100011011110110101101111110011100111001010001010001111001110111100...

output:

324123594

result:

ok 1 number(s): "324123594"

Test #14:

score: 10
Accepted
time: 30ms
memory: 6476kb

input:

110100110100110110001011100000011010000010000101100100001101100100110000101000111001111100001110001001101010110010111101000100111010001011001110101010001101111010000011000010110011000011100101110100000001011100111000101111010100001101011010100101110000010001101001000100111001101101110000101101011011...

output:

209285599

result:

ok 1 number(s): "209285599"

Subtask #8:

score: 10
Accepted

Dependency #6:

100%
Accepted

Test #15:

score: 10
Accepted
time: 674ms
memory: 5836kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

468567454

result:

ok 1 number(s): "468567454"

Test #16:

score: 10
Accepted
time: 1119ms
memory: 6844kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

12752860

result:

ok 1 number(s): "12752860"

Subtask #9:

score: 25
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #8:

100%
Accepted

Test #17:

score: 25
Accepted
time: 1422ms
memory: 8396kb

input:

101100010100101011010110001111101101001010000111001111000100110110010111101100011011011111010110000000011110000010100110111110110001101001101101001110101110011000010100100101000011000010000101011001011011000000100111011110100010000100001101011110100101110000100011000101100000111111100110000111010000...

output:

711712397

result:

ok 1 number(s): "711712397"

Test #18:

score: 25
Accepted
time: 1416ms
memory: 8184kb

input:

110101110100100010101100000110000110101101111100110011100111111110000101111001101001111000110111100111110111010001000010111111110000001001011110101110001011010010010011101000110110000110110101000100111000100110101111011101111101000010000101001001000010011011000011001100111111011000111000010000100111...

output:

171668334

result:

ok 1 number(s): "171668334"

Test #19:

score: 25
Accepted
time: 1174ms
memory: 7080kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

397846555

result:

ok 1 number(s): "397846555"

Test #20:

score: 25
Accepted
time: 1312ms
memory: 8424kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

592103795

result:

ok 1 number(s): "592103795"

Extra Test:

score: 0
Extra Test Passed