# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
61537 | 2018-07-26T07:16:37 Z | koosaga(#1775) | Election (BOI18_election) | C++11 | 3000 ms | 2152 KB |
#include<bits/stdc++.h> using namespace std; using pi = pair<int, int>; using lint = long long; const int MAXN = 500005; int a[MAXN], nxt[MAXN]; char str[MAXN]; vector<pi> v; int main(){ int n; scanf("%d",&n); scanf("%s", str + 1); for(int i=1; i<=n; i++){ if(str[i] == 'C') a[i] = a[i-1] + 1; else a[i] = a[i-1] - 1; } for(int i=0; i<=n; i++) v.push_back(pi(a[i], i)); sort(v.begin(), v.end()); for(int i=0; i<=n; i++){ auto k = lower_bound(v.begin(), v.end(), pi(a[i] - 1, i)); if(k == v.end() || k->first != a[i] - 1) nxt[i] = 1e9; else{ nxt[i] = k->second; } } int q; scanf("%d",&q); while(q--){ int l, r; scanf("%d %d",&l,&r); l--; int dap = -1e9; int cnt = 0; while(nxt[l] <= r){ cnt++; dap = max(dap - 1, *max_element(a + l, a + nxt[l])); l = nxt[l]; } dap = max(dap - 1, *max_element(a + l, a + r + 1)); printf("%d\n", cnt + dap - a[r]); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 408 KB | Output is correct |
2 | Correct | 5 ms | 408 KB | Output is correct |
3 | Correct | 5 ms | 540 KB | Output is correct |
4 | Correct | 7 ms | 540 KB | Output is correct |
5 | Correct | 6 ms | 540 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 408 KB | Output is correct |
2 | Correct | 5 ms | 408 KB | Output is correct |
3 | Correct | 5 ms | 540 KB | Output is correct |
4 | Correct | 7 ms | 540 KB | Output is correct |
5 | Correct | 6 ms | 540 KB | Output is correct |
6 | Correct | 1447 ms | 2152 KB | Output is correct |
7 | Execution timed out | 3015 ms | 2152 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 408 KB | Output is correct |
2 | Correct | 5 ms | 408 KB | Output is correct |
3 | Correct | 5 ms | 540 KB | Output is correct |
4 | Correct | 7 ms | 540 KB | Output is correct |
5 | Correct | 6 ms | 540 KB | Output is correct |
6 | Correct | 1447 ms | 2152 KB | Output is correct |
7 | Execution timed out | 3015 ms | 2152 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |