Submission #405147

#TimeUsernameProblemLanguageResultExecution timeMemory
405147tsarafElection (BOI18_election)C++17
0 / 100
3 ms332 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define ff first #define ss second #define all(x) (x).begin(), (x).end() const int N = 500 + 3; int n, Q; string s; void solve(){ cin >> n >> s >> Q; while(Q--){ int L, R; cin >> L >> R; --L; --R; bool vis[n]; memset(vis, false, sizeof(vis)); int sum = 0, ans = 0;; for(int i = L; i <= R; ++i){ int vote = (s[i] == 'C' ? +1 : -1); if(sum + vote < 0){ vis[i] = true; ++ans; } else { sum += vote; } } sum = 0; for(int i = R; i >= L; --i){ if(!vis[i]){ int vote = (s[i] == 'C' ? +1 : -1); if(sum + vote < 0){ vis[i] = true; ++ans; } else { sum += vote; } } } cout << ans << '\n'; } } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; // cin >> t; for(int i = 1; i <= t; i++){ // cout << "Case #" << i << ": "; solve(); } return 0; }

Compilation message (stderr)

election.cpp: In function 'int main()':
election.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
election.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...