| Task: | Bit strings |
| Sender: | Game of Nolife |
| Submission time: | 2016-05-28 13:15:21 +0300 |
| Language: | C++ |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.05 s | details |
| #2 | ACCEPTED | 0.90 s | details |
| #3 | ACCEPTED | 0.90 s | details |
| #4 | ACCEPTED | 0.83 s | details |
| #5 | ACCEPTED | 0.88 s | details |
| #6 | ACCEPTED | 0.90 s | details |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:79:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &tcs);
^
input/code.cpp:81: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 complex<ld> co;
const ld PI=atan2(0, -1);
vector<co> fft(vector<co> x, int d){
int n=(int)x.size();
for (int i=0;i<n;i++){
int u=0;
for (int j=1;j<n;j*=2){
u*=2;
if (i&j) u++;
}
if (i<u){
swap(x[i], x[u]);
}
}
for (int m=2;m<=n;m*=2){
co wm=exp(co{0, d*2*PI/m});
for (int k=0;k<n;k+=m){
co w=1;
for (int j=0;j<m/2;j++){
co t=w*x[k+j+m/2];
co u=x[k+j];
x[k+j]=u+t;
x[k+j+m/2]=u-t;
w*=wm;
}
}
}
if (d==-1){
for (int i=0;i<n;i++){
x[i]/=n;
}
}
return x;
}
vector<ll> conv(vector<ll> a, vector<ll> b){
int as=a.size();
int bs=b.size();
int n=1;
while (n<as+bs-1) n*=2;
vector<co> aa(n*2);
vector<co> 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<co> c(2*n);
for (int i=0;i<2*n;i++){
c[i]=aa[i]*bb[i];
}
c=fft(c, -1);
c.resize(as+bs-1);
vector<ll> r(as+bs-1);
for (int i=0;i<as+bs-1;i++){
r[i]=(ll)round(c[i].real());
}
return r;
}
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);
//string s;
/*
for (int i=0;i<100000;i++){
s+='1';
}*/
int n=strlen(s);
//int n=s.size();
vector<ll> 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<ll> lol=ct;
reverse(lol.begin(), lol.end());
vector<ll> cv=conv(ct, lol);
printf("%lld ", v0);
for (int i=n-1;i>=0;i--){
printf("%lld ", 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: ACCEPTED
| input |
|---|
| 1 001010110001110001110000110011... |
| correct output |
|---|
| 99028 198023 199224 198569 199... |
| user output |
|---|
| 99028 198023 199224 198569 199... |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 1 111010111001001100100101011110... |
| correct output |
|---|
| 99270 199585 198291 199812 198... |
| user output |
|---|
| 99270 199585 198291 199812 198... |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 20 001001010011101100110111110010... |
| correct output |
|---|
| 5022 10235 10021 9985 10019 99... |
| user output |
|---|
| 5022 10235 10021 9985 10019 99... |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 10 110101000110110101011011101010... |
| correct output |
|---|
| 9955 20073 20158 19923 20014 1... |
| user output |
|---|
| 9955 20073 20158 19923 20014 1... |
Test 6
Verdict: ACCEPTED
| input |
|---|
| 1 111111111111111111111111111111... |
| correct output |
|---|
| 968 100966 100967 100965 10096... |
| user output |
|---|
| 968 100966 100967 100965 10096... |
