이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
int n,q;
string s;
cin >> n >> s >> q;
for(int i = 0;i < q;i++){
int l,r;
cin >> l >> r;
vector <bool> vis(n,false);
int c = 0;
int t = 0;
for(int j = l-1; j < r;j++){
if(s.at(j) == 'C'){
c++;
}else{
t++;
if(t > c){
t--;
vis[j] = true;
}
}
}
c = 0;
t = 0;
for(int j = r-1; j >= l-1;j--){
if(s.at(j) == 'C'){
c++;
}else if(!vis[j]){
t++;
if(t > c){
t--;
vis[j] = true;
}
}
}
int res = 0;
for(int j = l-1;j < r;j++){
if(vis[j]){
res++;
}
}
cout << res << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |