Submission #730245

#TimeUsernameProblemLanguageResultExecution timeMemory
730245nguyentunglamElection (BOI18_election)C++17
28 / 100
3077 ms2248 KiB
#include<bits/stdc++.h> #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; const int N = 5e5 + 10; int a[N], b[N]; int main() { #define task "" cin.tie(0) -> sync_with_stdio(0); if (fopen ("task.inp", "r")) { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); } if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } int n; cin >> n; string s; cin >> s; s = " " + s; for(int i = 1; i <= n; i++) { if (s[i] == 'C') a[i] = 1; else a[i] = -1; } int q; cin >> q; while (q--) { for(int i = 1; i <= n; i++) b[i] = a[i]; int l, r, ans = 0; cin >> l >> r; int sum = 0; for(int i = l; i <= r; i++) { sum += b[i]; if (sum < 0) { sum = 0; ans++; b[i] = 0; } } sum = 0; int ans2 = 0; for(int i = r; i >= l; i--) { sum += b[i]; ans2 = max(ans2, -sum); } cout << ans + ans2 << endl; } }

Compilation message (stderr)

election.cpp: In function 'int main()':
election.cpp:13:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
election.cpp:14:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
election.cpp:17:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
election.cpp:18:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...