답안 #96555

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
96555 2019-02-10T09:34:24 Z josiftepe Election (BOI18_election) C++14
28 / 100
3000 ms 1956 KB
#include <bits/stdc++.h>

using namespace std;
const int maxn = 5e5 + 10;
int n;
string s;
bool visited[maxn];
int solve(int S, int E){
    int balance = 0;
    int ret = 0;
    memset(visited, false, sizeof visited);
    for(int i = S; i <= E; i ++){
        if(s[i] == 'C'){
            balance ++;
        }
        else{
            balance --;
        }
        if(balance < 0){
            balance = 0;
            visited[i] = true;
            ret ++;
        }

    }
    balance = 0;
    for(int i = E; i >= S; i --){
        if(s[i] == 'C'){
            balance ++;
        }
        else if(!visited[i] and s[i] == 'T'){
            balance --;
        }
        if(balance < 0){
            balance = 0;
            ret ++;
        }
    }
    return ret;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> s;
    int q;
    cin >> q;
    for(int i = 0; i < q; i ++){
        int a, b;
        cin >> a >> b;
        a --;
        b --;
        cout << solve(a, b) << endl;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 888 KB Output is correct
2 Correct 55 ms 888 KB Output is correct
3 Correct 58 ms 784 KB Output is correct
4 Correct 56 ms 888 KB Output is correct
5 Correct 57 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 888 KB Output is correct
2 Correct 55 ms 888 KB Output is correct
3 Correct 58 ms 784 KB Output is correct
4 Correct 56 ms 888 KB Output is correct
5 Correct 57 ms 1016 KB Output is correct
6 Execution timed out 3030 ms 1956 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 888 KB Output is correct
2 Correct 55 ms 888 KB Output is correct
3 Correct 58 ms 784 KB Output is correct
4 Correct 56 ms 888 KB Output is correct
5 Correct 57 ms 1016 KB Output is correct
6 Execution timed out 3030 ms 1956 KB Time limit exceeded
7 Halted 0 ms 0 KB -