# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
489589 | 2021-11-23T10:10:49 Z | pliam | Election (BOI18_election) | C++14 | 3000 ms | 2020 KB |
#include <bits/stdc++.h> #define MAXN 500000 using namespace std; int N,Q,a[MAXN],b[MAXN]; int main(){ scanf("%d",&N); for(int i=0;i<N;i++){ char c; scanf(" %c",&c); a[i]=(c=='C')?1:-1; } scanf("%d",&Q); for(int i=0;i<Q;i++){ int l,r; scanf("%d %d",&l,&r); l--; r--; int sum=0,countb=0; for(int pos=l;pos<=r;pos++){ b[pos]=0; sum+=a[pos]; if(sum<0){ b[pos]--; sum=0; countb++; } } sum=0; for(int pos=r;pos>=l;pos--){ sum+=a[pos]; if(sum<0){ b[pos]++; sum=0; } } sum=0; for(int pos=l;pos<=r;pos++){ sum+=b[pos]; if(sum<0) sum=0; } printf("%d\n",countb+sum); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 332 KB | Output is correct |
2 | Correct | 4 ms | 332 KB | Output is correct |
3 | Correct | 3 ms | 204 KB | Output is correct |
4 | Correct | 6 ms | 332 KB | Output is correct |
5 | Correct | 4 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 332 KB | Output is correct |
2 | Correct | 4 ms | 332 KB | Output is correct |
3 | Correct | 3 ms | 204 KB | Output is correct |
4 | Correct | 6 ms | 332 KB | Output is correct |
5 | Correct | 4 ms | 332 KB | Output is correct |
6 | Execution timed out | 3079 ms | 2020 KB | Time limit exceeded |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 332 KB | Output is correct |
2 | Correct | 4 ms | 332 KB | Output is correct |
3 | Correct | 3 ms | 204 KB | Output is correct |
4 | Correct | 6 ms | 332 KB | Output is correct |
5 | Correct | 4 ms | 332 KB | Output is correct |
6 | Execution timed out | 3079 ms | 2020 KB | Time limit exceeded |
7 | Halted | 0 ms | 0 KB | - |