답안 #861341

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
861341 2023-10-16T03:33:28 Z Aiperiii Election (BOI18_election) C++17
28 / 100
3000 ms 1576 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,q;
    cin>>n;
    string s;
    cin>>s;
    cin>>q;
    while(q--){
        int l,r;
        cin>>l>>r;l--;r--;
        int ans=0;
        vector <int> nu(s.size(),-1);
        int cnt2=0,cnt1=0;
        for(int i=l;i<=r;i++){
            if(s[i]=='C')cnt1++;
            else cnt2++;
            if(cnt2>cnt1){
                nu[i]=0;
                ans++;
                cnt2--;
            }
        }
        cnt2=0;cnt1=0;
        for(int i=r;i>=l;i--){
            if(s[i]=='C')cnt1++;
            else if(s[i]=='T' && nu[i]==-1)cnt2++;
            if(cnt2>cnt1){
                nu[i]=0;
                ans++;
                cnt2--;
            }
        }
        cout<<ans<<"\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 6 ms 348 KB Output is correct
3 Correct 5 ms 348 KB Output is correct
4 Correct 6 ms 348 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 6 ms 348 KB Output is correct
3 Correct 5 ms 348 KB Output is correct
4 Correct 6 ms 348 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
6 Execution timed out 3033 ms 1576 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 6 ms 348 KB Output is correct
3 Correct 5 ms 348 KB Output is correct
4 Correct 6 ms 348 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
6 Execution timed out 3033 ms 1576 KB Time limit exceeded
7 Halted 0 ms 0 KB -