답안 #111102

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
111102 2019-05-13T16:29:41 Z losmi247 Election (BOI18_election) C++14
28 / 100
3000 ms 2284 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5+23;

int a[N],n;
bool ode[N];
string s;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin >> n;
    cin >> s;
    for(int i = 1; i <= n; i++){
        a[i] = (s[i-1] == 'C' ? 1 : -1);
    }
    cin >> q;
    while(q--){
        int l,r;
        cin >> l >> r;
        int sol = 0,bal = 0;
        for(int i = l; i <= r; i++){
            ode[i] = 0;
        }
        for(int i = l; i <= r; i++){
            bal += a[i];
            if(bal < 0){
                ode[i] = 1;
                sol++;
                bal++;
            }
        }
        bal = 0;
        for(int i = r; i >= l; i--){
            if(ode[i]){
                continue;
            }
            bal += a[i];
            if(bal < 0){
                sol++;
                bal++;
            }
        }
        cout << sol << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 384 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
3 Correct 8 ms 384 KB Output is correct
4 Correct 11 ms 384 KB Output is correct
5 Correct 9 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 384 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
3 Correct 8 ms 384 KB Output is correct
4 Correct 11 ms 384 KB Output is correct
5 Correct 9 ms 384 KB Output is correct
6 Execution timed out 3030 ms 2284 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 384 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
3 Correct 8 ms 384 KB Output is correct
4 Correct 11 ms 384 KB Output is correct
5 Correct 9 ms 384 KB Output is correct
6 Execution timed out 3030 ms 2284 KB Time limit exceeded
7 Halted 0 ms 0 KB -