# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
69523 | 2018-08-21T07:23:42 Z | octopuses | Election (BOI18_election) | C++17 | 10 ms | 1072 KB |
//Giorgi Kldiashvili #include <bits/stdc++.h> #define ll long long #define fr first #define sc second #define M 1000000007ll using namespace std; const int N = 50020; char ch[N]; bool C[N]; int L[N], R[N]; int n, m, l, r; int A, B; int main() { scanf("%d\n", &n); scanf("%s", &ch); for(int i = 1; i <= n; ++ i) { int x = (ch[i - 1] == 'C')?1:-1; L[i] = L[i - 1] + x; } for(int i = n; i >= 1; -- i) { int x = (ch[i - 1] == 'C')?1:-1; R[i] = R[i + 1] + x; } scanf("%d", &m); while(m --) { scanf("%d %d", &l, &r); int last = 0; int answer = 0; for(int i = l; i <= r; ++ i) C[i] = false; for(int i = l; i <= r; ++ i) { last += (ch[i - 1] == 'C')?1:-1; if(last < 0) { answer ++; C[i] = true; last ++; } } last = 0; int now = 0; int S = answer; for(int i = r; i >= l; -- i) { if(C[i]) now ++; last += (ch[i - 1] == 'C')?1:-1; S = max(S, 0 - last - now + answer); } printf("%d\n", S); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 376 KB | Output is correct |
2 | Correct | 8 ms | 376 KB | Output is correct |
3 | Correct | 10 ms | 536 KB | Output is correct |
4 | Correct | 9 ms | 616 KB | Output is correct |
5 | Correct | 8 ms | 616 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 376 KB | Output is correct |
2 | Correct | 8 ms | 376 KB | Output is correct |
3 | Correct | 10 ms | 536 KB | Output is correct |
4 | Correct | 9 ms | 616 KB | Output is correct |
5 | Correct | 8 ms | 616 KB | Output is correct |
6 | Execution timed out | 3 ms | 1072 KB | Time limit exceeded (wall clock) |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 376 KB | Output is correct |
2 | Correct | 8 ms | 376 KB | Output is correct |
3 | Correct | 10 ms | 536 KB | Output is correct |
4 | Correct | 9 ms | 616 KB | Output is correct |
5 | Correct | 8 ms | 616 KB | Output is correct |
6 | Execution timed out | 3 ms | 1072 KB | Time limit exceeded (wall clock) |
7 | Halted | 0 ms | 0 KB | - |