# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
60910 | 2018-07-25T00:54:26 Z | spencercompton | Election (BOI18_election) | C++14 | 20 ms | 248 KB |
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s; cin >> s; int q; cin >> q; for(int i = 0; i<q; i++){ bool use[n]; for(int j = 0; j<n; j++){ use[j] = true; } int cur = 0; int l, r; cin >> l >> r; l--; r--; int ans = 0; vector<int> l1; for(int j = l; j<=r; j++){ if(s[j]=='T' && cur==0){ // ans++; l1.push_back(j); // use[j] = false; } else if(s[j]=='T'){ cur--; } else{ cur++; } } cur = 0; vector<int> l2; for(int j = r; j>=l; j--){ if(s[j]=='T' && cur==0){ // use[j] = false; l2.push_back(j); // ans++; } else if(s[j]=='T'){ cur--; } else if(s[j]=='C'){ cur++; } } if(l1.size()==0 || l2.size()==0){ ans = l1.size() + l2.size(); } else{ int b = l1[l1.size()-1]; int a = l2[l2.size()-1]; if(a > b){ ans = l1.size() + l2.size(); } else{ int m1 = 0; int m2 = 0; for(int j = 0; j<l1.size(); j++){ if(l1[j]>=a && l1[j]<=b){ m1++; } } for(int j = 0; j<l2.size(); j++){ if(l2[j]>=a && l2[j]<=b){ m2++; } } ans = l1.size()-m1 + l2.size()-m2 + max(m1,m2); } } cout << ans << endl; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 20 ms | 248 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 20 ms | 248 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 20 ms | 248 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |