Submission #68257

#TimeUsernameProblemLanguageResultExecution timeMemory
68257BruteforcemanElection (BOI18_election)C++11
28 / 100
3044 ms3124 KiB
#include "bits/stdc++.h" using namespace std; int a[500010]; int p[500010]; int solve(int l, int r) { int cur = 0; int ans = 0; int mx = 0; for(int i = l; i <= r; i++) { cur += a[i]; if(cur < 0) { ++ans; cur = 0; } mx = max(mx, cur); } ans += mx - cur; return ans; } char s[500010]; int main(int argc, char const *argv[]) { int n; scanf("%d", &n); scanf("%s", s); for(int i = 1; i <= n; i++) { a[i] = s[i - 1] == 'C' ? 1 : -1; } int q; scanf("%d", &q); while(q--) { int l, r; scanf("%d %d", &l, &r); printf("%d\n", solve(l, r)); } return 0; }

Compilation message (stderr)

election.cpp: In function 'int main(int, const char**)':
election.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
election.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", s);
  ~~~~~^~~~~~~~~
election.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &q);
  ~~~~~^~~~~~~~~~
election.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &l, &r);
   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...