Submission #565627

#TimeUsernameProblemLanguageResultExecution timeMemory
5656271zaid1Election (BOI18_election)C++14
28 / 100
3072 ms540 KiB
#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 (stderr)

election.cpp: In function 'long long int res(std::string)':
election.cpp:12:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for (int i = 0; i < s.size(); i++) {
      |                     ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...