# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
101798 | 2019-03-20T10:11:40 Z | tushar_2658 | Election (BOI18_election) | C++14 | 12 ms | 384 KB |
#include "bits/stdc++.h" using namespace std; const int maxn = 7e4 + 5; int arr[maxn], arr1[maxn], arr2[maxn], n; string s; int solve(int l, int r){ int cnt = 0; int ans = 0, mx = 0; for(int i=l; i<=r; i++){ cnt += arr[i]; if(cnt < 0 && arr[i] == 1 && arr[i-1] == -1 && i > l){ mx += abs(cnt-1); cnt = 0; } } if(cnt < 0){ mx += abs(cnt); } int mxx = 0; cnt = 0; for(int i=r; i>=l; i--){ cnt += arr[i]; if(cnt < 0 && arr[i] == 1 && arr[i+1] == -1 && i < r){ mxx += abs(cnt-1); cnt = 0; } } if(cnt < 0){ mxx += abs(cnt); } return max(mx, mxx); } int main(){ //freopen("in.txt", "r", stdin); cin>>n; cin>>s; for(int i=1; i<=n; i++){ if(s[i-1] == 'C')arr[i] = 1; else arr[i] = -1; } int q; cin>>q; while(q--){ int l, r; cin>>l>>r; cout<<solve(l, r)<<endl; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 12 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 12 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 12 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |