Submission #571493

#TimeUsernameProblemLanguageResultExecution timeMemory
571493Doanxem99Election (BOI18_election)C++14
0 / 100
53 ms47444 KiB
#include <bits/stdc++.h> using namespace std; #define ar array< int , 2> #define MASK(i) (1 << (i)) #define BIT(x, i) (((x) >> (i)) & 1) const int MAX = 1e6 + 1000; int n, k, x, y; char c; map< char , int > d[MAX]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> c; if (c == 'C') { d[i]['C'] = d[i - 1]['C'] + 1; d[i]['T'] = d[i - 1]['T']; } else { d[i]['T'] = d[i - 1]['T'] + 1; d[i]['C'] = d[i - 1]['C']; } } cin >> k; for (int i = 1; i <= k; i++) { cin >> x >> y; //cout << d[y]['C'] - d[x - 1]['C'] << '\n' ; int ans = 0; for (int j = x; j <= y; j++) { ans = max(ans, d[j]['T'] - d[x - 1]['T'] - d[j]['C'] + d[x - 1]['T']); } for (int j = y; j >= x; j--) { ans = max(ans, d[y]['T'] - d[j - 1]['T'] - d[y]['C'] + d[j - 1]['C']); } cout << ans << '\n' ; } } /* 11 CCCTTTTTTCC 3 1 11 4 9 1 6 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...