Submission #852923

#TimeUsernameProblemLanguageResultExecution timeMemory
852923BenmathElection (BOI18_election)C++14
28 / 100
3033 ms1980 KiB
/****************************************************************************** Online C++ Compiler. Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <bits/stdc++.h> using namespace std; int main() { int n, q; cin >> n; string s; cin >> s; cin >> q; vector<int>ans; while (q--){ int a, b; cin >> a >> b; a--; b--; vector<int>v; for(int i = a; i <= b; i++){ if(s[i] == 'C'){ v.push_back(1); }else{ v.push_back(-1); } } int sum = 0; for(int i = 0; i < v.size(); i++){ sum = sum + v[i]; if(sum < 0){ v[i] = 0; sum = 0; } } sum = 0; for(int i = v.size()-1; i >= 0; i--){ sum = sum + v[i]; if(sum < 0){ v[i] = 0; sum = 0; } } int brojac = 0; for(int i = 0; i < v.size(); i++){ if(v[i] == 0){ brojac++; } } ans.push_back(brojac); } for (int i = 0; i < ans.size(); i++){ cout << ans[i] << endl; } }

Compilation message (stderr)

election.cpp: In function 'int main()':
election.cpp:35:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for(int i = 0; i < v.size(); i++){
      |                        ~~^~~~~~~~~~
election.cpp:51:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for(int i = 0; i < v.size(); i++){
      |                        ~~^~~~~~~~~~
election.cpp:58:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for (int i = 0; i < ans.size(); i++){
      |                     ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...