CSES - HIIT Open 2016 - Results
Submission details
Task:Bit strings
Sender:Game of Nolife
Submission time:2016-05-28 13:04:03 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.06 sdetails
#2--details
#3--details
#4--details
#5--details
#6--details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:104:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &tcs);
                   ^
input/code.cpp:106:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", s);
                 ^

Code

#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef __int128 lll;
const lll mod=2097152000007340033;
const lll root=2014907510281342032;
const lll root_pw=1<<20;

lll pot(lll x, lll p){
	if (p==0) return 1;
	if (p%2==0){
		x=pot(x, p/2);
		return (x*x)%mod;
	}
	return (x*pot(x, p-1))%mod;
}

lll inv(lll x){
	return pot(x, mod-2);
}

vector<lll> fft(vector<lll> a, int d){
	lll root_1=inv(root);
	int n=(int)a.size();
	for (int i=1,j=0;i<n;i++){
		int bit=n>>1;
		for (;j>=bit;bit>>=1){
			j-=bit;
		}
		j+=bit;
		if (i<j) swap(a[i], a[j]);
	}
	for (int len=2;len<=n;len<<=1){
		lll wlen=root;
		if (d==-1){
			wlen=root_1;
		}
		for (int i=len;i<root_pw;i<<=1) wlen=(wlen*wlen)%mod;
		for (int i=0;i<n;i+=len){
			lll w=1;
			for (int j=0;j<len/2;j++){
				lll u=a[i+j];
				lll v=(a[i+j+len/2]*w)%mod;
				if (u+v<mod){
					a[i+j]=u+v;
				}
				else{
					a[i+j]=u+v-mod;
				}
				if (u-v>=0){
					a[i+j+len/2]=u-v;
				}
				else{
					a[i+j+len/2]=u-v+mod;
				}
				w=(w*wlen)%mod;
			}
		}
	}
	if (d==-1){
		lll nrev=inv(n);
		for (int i=0;i<n;i++){
			a[i]=(a[i]*nrev)%mod;
		}
	}
	return a;
}

vector<lll> conv(vector<lll> a, vector<lll> b){
	int as=a.size();
	int bs=b.size();
	int n=1;
	while (n<as+bs-1) n*=2;
	vector<lll> aa(n*2);
	vector<lll> bb(n*2);
	for (int i=0;i<as;i++){
		aa[i]=a[i];
	}
	for (int i=0;i<bs;i++){
		bb[i]=b[i];
	}
	aa=fft(aa, 1);
	bb=fft(bb, 1);
	vector<lll> c(2*n);
	for (int i=0;i<2*n;i++){
		c[i]=(aa[i]*bb[i])%mod;
	}
	c=fft(c, -1);
	c.resize(as+bs-1);
	return c;
}

char s[101010];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int tcs;
	scanf("%d", &tcs);
	for (int tc=0;tc<tcs;tc++){
		scanf("%s", s);
		/*
		for (int i=0;i<100000;i++){
			s+='1';
		}
		*/
		int n=strlen(s);
		vector<lll> ct(n+1);
		ct[0]=1;
		int t=0;
		ll v0=0;
		ll c0=0;
		for (int i=0;i<n;i++){
			if (s[i]=='1') {
				t++;
				c0=0;
			}
			else{
				c0++;
				v0+=c0;
			}
			ct[t]++;
		}
		vector<lll> lol=ct;
		reverse(lol.begin(), lol.end());
		vector<lll> cv=conv(ct, lol);
		printf("%lld ", v0);
		for (int i=n-1;i>=0;i--){
			printf("%lld ", (ll)cv[i]);
		}
		printf("\n");
	}
}


Test details

Test 1

Verdict: ACCEPTED

input
20
00011000100111001100
00001001111111100010
10110011110101111101
01111011010010100111
...

correct output
21 33 39 30 23 20 25 7 12 0 0 ...

user output
21 33 39 30 23 20 25 7 12 0 0 ...

Test 2

Verdict:

input
1
001010110001110001110000110011...

correct output
99028 198023 199224 198569 199...

user output
(empty)

Test 3

Verdict:

input
1
111010111001001100100101011110...

correct output
99270 199585 198291 199812 198...

user output
(empty)

Test 4

Verdict:

input
20
001001010011101100110111110010...

correct output
5022 10235 10021 9985 10019 99...

user output
(empty)

Test 5

Verdict:

input
10
110101000110110101011011101010...

correct output
9955 20073 20158 19923 20014 1...

user output
(empty)

Test 6

Verdict:

input
1
111111111111111111111111111111...

correct output
968 100966 100967 100965 10096...

user output
(empty)