Submission #855857

# Submission time Handle Problem Language Result Execution time Memory
855857 2023-10-02T03:51:35 Z NeroZein Election (BOI18_election) C++17
28 / 100
3000 ms 2532 KB
#include "bits/stdc++.h"
#define int long long
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n); 
  for (int i = 0; i < n; ++i) {
    char c;
    cin >> c;
    a[i] = (c == 'C' ? 1 : -1); 
  }
  int q;
  cin >> q;
  auto solve = [&](int l, int r) {
    vector<int> nullified(n); 
    int sum = 0;
    for (int i = l; i <= r; ++i) {
      if (sum + a[i] < 0) nullified[i] = 1;
      else sum += a[i]; 
    }
    sum = 0;
    for (int i = r; i >= l; --i) {
      if (nullified[i]) continue;
      if (sum + a[i] < 0) nullified[i] = 1;
      else sum += a[i]; 
    }
    return accumulate(nullified.begin(), nullified.end(), 0); 
  };
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << solve(l - 1, r - 1) << '\n';
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 5 ms 468 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 5 ms 468 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
6 Execution timed out 3081 ms 2532 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 5 ms 468 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
6 Execution timed out 3081 ms 2532 KB Time limit exceeded
7 Halted 0 ms 0 KB -