CSES - Practice Contest 2024 - Results
Submission details
Task:Bit strings
Sender:asdf
Submission time:2024-09-28 14:30:01 +0300
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2--details
#3--details
#4ACCEPTED0.07 sdetails
#5ACCEPTED0.12 sdetails
#6--details

Code

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

const int N = 1e5 + 5;


int l[N], z[N], a[N];
int c[N];
void solve()
{
    string s;
    cin >> s;

    int m = s.length(), k=0;
    memset(l, 0, sizeof(int)*(m+5));
    memset(z, 0, sizeof(int)*(m+5));
    memset(a, 0, sizeof(int)*(m+5));

    int last = -1;
    for(int i=0; i<m; i++)
    {
        z[i] = z[i-1];
        if(s[i]=='1')
        {
            // in one
            k++;
            l[k] = z[i] - z[last] + 1;
            last = i;
        } else {
            // in zero
            z[i]+=1;
        }
    }
    l[k+1] = z[m-1] - z[last] + 1;

    for(int i=1; i<=k; i++)
    {
        a[0] += c[l[i] - 1];
        for(int j=0; i+j<=k; j++)
            a[j+1] += l[i] * l[i+j+1];
    }
    a[0] += c[l[k+1] - 1];

    for(int i=0; i<=m; i++)
    {
        // all numbers
        cout<<a[i]<<" ";
    }
    cout<<endl;
}


signed main() {
    cin.tie(0)->sync_with_stdio(0);

    int t;
    cin >> t;

    c[1] = 1;
    for(int i=2; i<=1e5; i++)
        c[i] = c[i-1] + i;
    
    while (t--) {
        solve();
    }
}

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 ...
Truncated

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: ACCEPTED

input
20
001001010011101100110111110010...

correct output
5022 10235 10021 9985 10019 99...

user output
5022 10235 10021 9985 10019 99...
Truncated

Test 5

Verdict: ACCEPTED

input
10
110101000110110101011011101010...

correct output
9955 20073 20158 19923 20014 1...

user output
9955 20073 20158 19923 20014 1...
Truncated

Test 6

Verdict:

input
1
111111111111111111111111111111...

correct output
968 100966 100967 100965 10096...

user output
(empty)