Task: | Bit strings |
Sender: | asdf |
Submission time: | 2024-09-28 13:57:11 +0300 |
Language: | C++ (C++20) |
Status: | READY |
Result: | TIME LIMIT EXCEEDED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.01 s | details |
#2 | TIME LIMIT EXCEEDED | -- | details |
#3 | TIME LIMIT EXCEEDED | -- | details |
#4 | ACCEPTED | 0.07 s | details |
#5 | ACCEPTED | 0.12 s | details |
#6 | TIME LIMIT EXCEEDED | -- | details |
Code
#include <bits/stdc++.h> #include <stdio.h> using namespace std; #define int long long const int N = 1e5 + 5; int l[N], r[N], z[N], a[N]; int c[N]; void solve() { memset(l, 0, sizeof(l)); memset(r, 0, sizeof(r)); memset(z, 0, sizeof(z)); memset(a, 0, sizeof(a)); string s; cin >> s; int m = s.length(), k=0; int last = -1; for(int i=0; i<m; i++) { z[i] = z[i-1]; if(s[i]=='1') { // in one k++; if(last == -1) { l[k] = z[i]; } else { l[k] = r[k-1] = z[i] - z[last]; } last = i; } else { // in zero z[i]+=1; } } r[k] = z[m-1] - z[last]; for(int i=1; i<=k; i++) { a[0] += c[l[i]]; for(int j=0; i+j<=k; j++) { // if(l[i] == 0 && r[i+j] == 0) // continue; // // a[j+1] += (l[i]>0? l[i]:1) * (r[i+j]>0? r[i+j]:1); a[j+1] += (l[i] + 1) * (r[i+j] + 1); } } a[0] += c[r[k]]; 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: TIME LIMIT EXCEEDED
input |
---|
1 001010110001110001110000110011... |
correct output |
---|
99028 198023 199224 198569 199... |
user output |
---|
(empty) |
Test 3
Verdict: TIME LIMIT EXCEEDED
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: TIME LIMIT EXCEEDED
input |
---|
1 111111111111111111111111111111... |
correct output |
---|
968 100966 100967 100965 10096... |
user output |
---|
(empty) |