Submission #760471

# Submission time Handle Problem Language Result Execution time Memory
760471 2023-06-17T15:57:59 Z vjudge1 Election (BOI18_election) C++17
28 / 100
3000 ms 2232 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "C:\GCC\debug.h"
#else
#define debug(...) void(42)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    if (s[i] == 'C') {
      a[i] = +1;
    } else {
      a[i] = -1;
    }
  }

  auto Ret = [&](int l, int r) {
    int balance = 0;
    int res = 0;
    vector<int> b(n);
    for (int i = l; i <= r; i++) {
      if (balance + a[i] >= 0) {
        balance += a[i];
      } else {
        res += 1;
        b[i] = true;
      }
    }

    balance = 0;
    for (int i = r; i >= l; i--) {
      if (b[i]) {
        continue;
      }
      if (balance + a[i] >= 0) {
        balance += a[i];
      } else {
        res += 1;
        b[i] = true;
      }
    }
    return res;
  };

  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    --l, --r;

    cout << Ret(l, r) << '\n';
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 3 ms 328 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 3 ms 328 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 2113 ms 2232 KB Output is correct
7 Execution timed out 3052 ms 1724 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 3 ms 328 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 2113 ms 2232 KB Output is correct
7 Execution timed out 3052 ms 1724 KB Time limit exceeded
8 Halted 0 ms 0 KB -