이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |