# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
489588 | 2021-11-23T10:09:55 Z | pliam | Election (BOI18_election) | C++14 | 6 ms | 332 KB |
#include <bits/stdc++.h> #define MAXN 5000 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 | 4 ms | 332 KB | Output is correct |
4 | Correct | 6 ms | 332 KB | Output is correct |
5 | Correct | 5 ms | 308 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 | 4 ms | 332 KB | Output is correct |
4 | Correct | 6 ms | 332 KB | Output is correct |
5 | Correct | 5 ms | 308 KB | Output is correct |
6 | Incorrect | 1 ms | 332 KB | Output isn't correct |
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 | 4 ms | 332 KB | Output is correct |
4 | Correct | 6 ms | 332 KB | Output is correct |
5 | Correct | 5 ms | 308 KB | Output is correct |
6 | Incorrect | 1 ms | 332 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |