답안 #1054823

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054823 2024-08-12T12:26:14 Z MercubytheFirst Election (BOI18_election) C++17
28 / 100
3000 ms 1108 KB
#include "bits/stdc++.h"
#define endl '\n'
using namespace std;


void solve() {
  int n;
  string s;
  cin >> n >> s;
  int Q;
  cin >> Q;
  while(Q--) {
    int l, r;
    cin >> l >> r;
    --l;
    const int len = r - l;
    string tmp = s.substr(l, len);
    int ans = 0, balance = 0;
    for(int i = 0; i < len; ++i) {
      assert(balance >= 0);
      if(tmp[i] == 'C') {
        balance++;
        continue;
      }
      assert(tmp[i] == 'T');
      if(balance == 0) {
        tmp[i] = 'X';
        ++ans;
      }
      else {
        balance--;
      }
    }
    reverse(tmp.begin(), tmp.end());
    balance = 0;
    for(int i = 0; i < len; ++i) {
      assert(balance >= 0);
      if(tmp[i] == 'C') {
        balance++;
        continue;
      }
      else if(tmp[i] == 'X') {
        continue;
      }
      assert(tmp[i] == 'T');
      if(balance == 0) {
        tmp[i] = 'X';
        ++ans;
      }
      else {
        balance--;
      }
    }
    cout << ans << endl;
  }
}



signed main()  {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // signed t; cin >> t; while(t--)
    solve();
}





# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 4 ms 348 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 4 ms 348 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
6 Execution timed out 3073 ms 1108 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 4 ms 348 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
6 Execution timed out 3073 ms 1108 KB Time limit exceeded
7 Halted 0 ms 0 KB -