# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
60910 | spencercompton | Election (BOI18_election) | C++14 | 20 ms | 248 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
int q;
cin >> q;
for(int i = 0; i<q; i++){
bool use[n];
for(int j = 0; j<n; j++){
use[j] = true;
}
int cur = 0;
int l, r;
cin >> l >> r;
l--;
r--;
int ans = 0;
vector<int> l1;
for(int j = l; j<=r; j++){
if(s[j]=='T' && cur==0){
// ans++;
l1.push_back(j);
// use[j] = false;
}
else if(s[j]=='T'){
cur--;
}
else{
cur++;
}
}
cur = 0;
vector<int> l2;
for(int j = r; j>=l; j--){
if(s[j]=='T' && cur==0){
// use[j] = false;
l2.push_back(j);
// ans++;
}
else if(s[j]=='T'){
cur--;
}
else if(s[j]=='C'){
cur++;
}
}
if(l1.size()==0 || l2.size()==0){
ans = l1.size() + l2.size();
}
else{
int b = l1[l1.size()-1];
int a = l2[l2.size()-1];
if(a > b){
ans = l1.size() + l2.size();
}
else{
int m1 = 0;
int m2 = 0;
for(int j = 0; j<l1.size(); j++){
if(l1[j]>=a && l1[j]<=b){
m1++;
}
}
for(int j = 0; j<l2.size(); j++){
if(l2[j]>=a && l2[j]<=b){
m2++;
}
}
ans = l1.size()-m1 + l2.size()-m2 + max(m1,m2);
}
}
cout << ans << endl;
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |