답안 #859372

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
859372 2023-10-10T05:44:30 Z 1075508020060209tc Election (BOI18_election) C++14
28 / 100
3000 ms 6400 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long


void solve(vector<int>ar){
int n=ar.size()-1;
vector<int>br=ar;
priority_queue<int>pq;
int tot=0;
int ret=0;
for(int i=1;i<=n;i++){
    tot+=ar[i];
    if(tot<0){
        tot+=1;br[i]=0;ret++;
    }
}
tot=0;
for(int i=n;i>=1;i--){
   tot+=br[i];
    if(tot<0){
        tot+=1;br[i]=0;ret++;
    }
}
cout<<ret<<endl;

}


int n;int Q;
int ar[500005];

signed main(){
cin>>n;
{
    string s;
    cin>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='C'){
            ar[i+1]=1;
        }else{
            ar[i+1]=-1;
        }
    }
}
cin>>Q;
while(Q--){
    int l;int r;
    cin>>l>>r;
    vector<int>vc;
    vc.push_back(0);
    for(int i=l;i<=r;i++){
        vc.push_back(ar[i]);
    }
    solve(vc);

}

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