이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
bool mark[maxn];
int main () {
int n, q;
string s;
cin >> n >> s >> q;
for (int i = 0; i < q; i++) {
memset (mark, 0, sizeof mark);
int l, r;
cin >> l >> r;
l --, r --;
int cnt = 0, cntr = 0, ans = 0;
for (int j = l; j <= r; j++) {
if (s[j] == 'C') {
if (cntr > 0) {
cntr --;
ans --;
if (cnt == -1) {
cnt ++;
ans ++;
}
}
cnt ++;
}
else {
cntr ++;
ans ++;
cnt --;
if (cnt == -1) {
cnt ++;
cntr --;
}
}
// cout << j << " -> " << cnt << " " << cntr << " " << ans << endl;
}
cout << ans << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |