# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
565627 | 2022-05-21T07:48:02 Z | 1zaid1 | Election (BOI18_election) | C++14 | 3000 ms | 540 KB |
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define int long long typedef long long ll; const int M = 2e6 + 5, MOD = 1e9+7; int res(string s) { int ans = 0; int a = 0, b = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'T') a++; if (s[i] == 'C') b++; if (a > b) { a--; s[i] = 0; ans++; } } a = 0; b = 0; for (int i = s.size()-1; i >= 0; i--) { if (s[i] == 'T') a++; if (s[i] == 'C') b++; if (a > b) { a--; s[i] = 0; ans++; } } return ans; } signed main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); srand(time(0)); int n; cin >> n; string s; cin >> s; int t; cin >> t; while (t--) { int l, r; cin >> l >> r; cout << res(s.substr(l-1, r-l+1)) << endl; } return 0; } /* 11 CCCTTTTTTCC 3 1 11 4 9 1 6 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 340 KB | Output is correct |
2 | Correct | 7 ms | 340 KB | Output is correct |
3 | Correct | 7 ms | 340 KB | Output is correct |
4 | Correct | 6 ms | 352 KB | Output is correct |
5 | Correct | 4 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 340 KB | Output is correct |
2 | Correct | 7 ms | 340 KB | Output is correct |
3 | Correct | 7 ms | 340 KB | Output is correct |
4 | Correct | 6 ms | 352 KB | Output is correct |
5 | Correct | 4 ms | 340 KB | Output is correct |
6 | Execution timed out | 3072 ms | 540 KB | Time limit exceeded |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 340 KB | Output is correct |
2 | Correct | 7 ms | 340 KB | Output is correct |
3 | Correct | 7 ms | 340 KB | Output is correct |
4 | Correct | 6 ms | 352 KB | Output is correct |
5 | Correct | 4 ms | 340 KB | Output is correct |
6 | Execution timed out | 3072 ms | 540 KB | Time limit exceeded |
7 | Halted | 0 ms | 0 KB | - |