Task: | Zero Game |
Sender: | liianvaikeitatehtäviä |
Submission time: | 2017-10-03 18:58:51 +0300 |
Language: | C++ |
Status: | READY |
Result: | RUNTIME ERROR |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.11 s | details |
#2 | ACCEPTED | 0.11 s | details |
#3 | ACCEPTED | 0.12 s | details |
#4 | RUNTIME ERROR | 0.33 s | details |
#5 | RUNTIME ERROR | 0.34 s | details |
#6 | RUNTIME ERROR | 0.32 s | details |
#7 | RUNTIME ERROR | 0.34 s | details |
#8 | RUNTIME ERROR | 0.31 s | details |
#9 | RUNTIME ERROR | 0.36 s | details |
#10 | RUNTIME ERROR | 0.29 s | details |
#11 | RUNTIME ERROR | 0.35 s | details |
#12 | RUNTIME ERROR | 0.33 s | details |
#13 | RUNTIME ERROR | 0.37 s | details |
#14 | RUNTIME ERROR | 0.32 s | details |
#15 | RUNTIME ERROR | 0.36 s | details |
#16 | RUNTIME ERROR | 0.33 s | details |
#17 | RUNTIME ERROR | 0.36 s | details |
#18 | RUNTIME ERROR | 0.31 s | details |
#19 | WRONG ANSWER | 1.76 s | details |
#20 | WRONG ANSWER | 1.71 s | details |
#21 | WRONG ANSWER | 1.77 s | details |
#22 | WRONG ANSWER | 1.65 s | details |
#23 | WRONG ANSWER | 1.70 s | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:97:6: warning: unused variable 'zerosLeft' [-Wunused-variable] int zerosLeft = 0; ^
Code
#include <bits/stdc++.h> using namespace std; int ok[1010101]; const int N = 1<<20; int st[2*N]; vector<int> mx[20]; int so[N]; int qu[N]; int sumOnes(int a, int b) { if(b < 0) return 0; if(b < a) { return 0; } return so[b+1] - so[a]; } int sumZeros(int a, int b) { if(b < 0) return 0; if(b < a) return 0; return b-a+1 - (sumOnes(a, b)); } int getMax(int a, int b) { if(a == b) return a; int q = log(b-a+1)/log(2); int sz = 1<<q; // cout<<a<<' '<<b<<' '<<q<<' '<<sz<<' '<<mx[q][a]<<' '<<mx[q][b-sz+1]<<endl; return max(mx[q][a], mx[q][b-sz+1]); } int ans[N]; int main() { for(int i = 0; i < 20; ++i) mx[i].resize(N); string s; cin>>s; int q; cin>>q; for(int i = 0; i < q; ++i) { cin>>qu[i]; } int n = s.size(); for(int i = 0; i < n; ++i) s[i] -= '0'; for(int i = 0; i < n; ++i) { so[i+1] = so[i] + s[i]; } if(sumZeros(0, n-1) == 0) { for(int j = 0; j < q ;++j) cout<<0<<'\n'; return 0; } ok[n] = n; for(int i = n-1; i >= 0; --i) { int sum = 0; ok[i] = n; for(int j = i; j < n;) { if(s[j] == 0) sum++; else sum--; if(sum >= 0) { ok[i] = j; break; } //eli nyt sum < 0 if(ok[j+1] != j+1){ j = ok[j+1]+1; } else ++j; } } /* for(int i = 0; i < n; ++i) { cout<<i<<' '<<ok[i]<<'\n'; } cout<<'\n'; */ for(int i = 0; i < n; ++i) { mx[0][i] = i; } int siz = 1; for(int i = 1; i < 20; ++i) { for(int j = 0; j < n; ++j) { int q = mx[i-1][j]; int w = mx[i-1][j+siz]; if(ok[q] > ok[w]) { mx[i][j] = q; } else mx[i][j] = w; //if(j < 10) cout<<q<<' '<<w<<' '<<mx[i][j]<<" "; //if(j < 10) cout<<mx[i][j]<<' '; } siz *= 2; //cout<<'\n'; } //cout<<getMax(0, 5)<<' '<<getMax(7, 10)<<endl; //getMax(0, 5); //getMax(7, 10); int qpos[N] = {0}; int qused[N] = {0}; int zerosLeft = 0; //for(int i = 0; i < n; ++i) if(s[i] == 0) ++zerosLeft; for(int i = 0; i < q; ++i) qused[i] = (s[0] == 1); for(int i = 0; i < n; ++i) { for(int j = 0; j < q; ++j) { while(qpos[j] < n-1) { if(s[qpos[j]+1] == 0) ++qpos[j]; else if(qused[j] < qu[j]) { ++qused[j]; ++qpos[j]; } else break; } /* if(j == 0) { cout<<i<<' '<<qpos[j]<<' '; } */ //cout<<j<<' '<<qpos[j]<<' '<<qused[j]<<' '<<n<<' '<<qu[j]<<endl; int z = getMax(i, qpos[j]); //koordinaatti /* if(j == 0) { cout<<z<<' '<<ok[z]<<'\n'; } */ if(ok[z] > qpos[j]) { int score = sumZeros(i, z-1) + min(sumZeros(z, n-1), qu[j] - sumOnes(i, z-1)); // if(j == 0) cout<<sumZeros(i, z-1)<<' '<<sumZeros(z, n-1)<<'\n'; ans[j] = max(score, ans[j]); } else { ans[j] = max(ans[j], sumZeros(i, qpos[j])); } if(s[i] == 1) { --qused[j]; } } } for(int i = 0; i < q; ++i) { cout<<ans[i]<<'\n'; } }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
0000110000111110 5 1 2 3 ... |
correct output |
---|
5 8 9 9 9 |
user output |
---|
5 8 9 9 9 |
Test 2
Verdict: ACCEPTED
input |
---|
0 3 1 2 1000000 |
correct output |
---|
1 1 1 |
user output |
---|
1 1 1 |
Test 3
Verdict: ACCEPTED
input |
---|
1 3 1 2 1000000 |
correct output |
---|
0 0 0 |
user output |
---|
0 0 0 |
Test 4
Verdict: RUNTIME ERROR
input |
---|
101010000100110111100010011111... |
correct output |
---|
27508 3952 38438 41043 45967 ... |
user output |
---|
(empty) |
Test 5
Verdict: RUNTIME ERROR
input |
---|
010011011010011111000010000101... |
correct output |
---|
2539 44377 14738 16082 24442 ... |
user output |
---|
(empty) |
Test 6
Verdict: RUNTIME ERROR
input |
---|
100111100001001111101011110011... |
correct output |
---|
32545 50046 1718 28159 50078 ... |
user output |
---|
(empty) |
Test 7
Verdict: RUNTIME ERROR
input |
---|
100010110100001011000100010110... |
correct output |
---|
5417 10857 39391 7219 16158 ... |
user output |
---|
(empty) |
Test 8
Verdict: RUNTIME ERROR
input |
---|
101101110000000011101010001001... |
correct output |
---|
28572 3982 4294 42653 15568 ... |
user output |
---|
(empty) |
Test 9
Verdict: RUNTIME ERROR
input |
---|
100010010011011100110101100110... |
correct output |
---|
39423 42215 20939 22244 6606 ... |
user output |
---|
(empty) |
Test 10
Verdict: RUNTIME ERROR
input |
---|
101011100110001100000001001011... |
correct output |
---|
49496 38784 33144 32488 31351 ... |
user output |
---|
(empty) |
Test 11
Verdict: RUNTIME ERROR
input |
---|
001111010111101100101001011100... |
correct output |
---|
6917 21861 18615 25072 18596 ... |
user output |
---|
(empty) |
Test 12
Verdict: RUNTIME ERROR
input |
---|
010100101011111011110010100011... |
correct output |
---|
43850 8690 13226 41153 42409 ... |
user output |
---|
(empty) |
Test 13
Verdict: RUNTIME ERROR
input |
---|
010001110100010111010000110011... |
correct output |
---|
39994 40744 20457 16265 47047 ... |
user output |
---|
(empty) |
Test 14
Verdict: RUNTIME ERROR
input |
---|
111111100111110001110100000010... |
correct output |
---|
459798 278541 204171 233150 5113 ... |
user output |
---|
(empty) |
Test 15
Verdict: RUNTIME ERROR
input |
---|
000010001111100111111000010011... |
correct output |
---|
446184 279158 311949 469694 260672 ... |
user output |
---|
(empty) |
Test 16
Verdict: RUNTIME ERROR
input |
---|
000001011010011011010000001111... |
correct output |
---|
85605 392194 287645 324684 389995 ... |
user output |
---|
(empty) |
Test 17
Verdict: RUNTIME ERROR
input |
---|
100111001111000111001010110100... |
correct output |
---|
415271 228907 279960 376429 366346 ... |
user output |
---|
(empty) |
Test 18
Verdict: RUNTIME ERROR
input |
---|
011101101010000110000010011001... |
correct output |
---|
473458 106311 430917 402707 240473 ... |
user output |
---|
(empty) |
Test 19
Verdict: WRONG ANSWER
input |
---|
101001101011100000001000111000... |
correct output |
---|
1776 2430 1210 1495 2085 ... |
user output |
---|
1759 2412 1198 1488 2068 ... |
Test 20
Verdict: WRONG ANSWER
input |
---|
011110000111000101000001111000... |
correct output |
---|
1572 2349 3106 1565 2248 ... |
user output |
---|
1563 2306 3033 1556 2213 ... |
Test 21
Verdict: WRONG ANSWER
input |
---|
110011111011001101011001000000... |
correct output |
---|
410 2693 504 1777 1380 ... |
user output |
---|
407 2651 504 1756 1380 ... |
Test 22
Verdict: WRONG ANSWER
input |
---|
000110111101111111110001110000... |
correct output |
---|
2679 2282 564 1755 845 ... |
user output |
---|
2595 2224 547 1706 824 ... |
Test 23
Verdict: WRONG ANSWER
input |
---|
111011100111000001100000001100... |
correct output |
---|
820 787 2553 911 3095 ... |
user output |
---|
820 787 2487 909 3022 ... |