답안 #68912

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68912 2018-08-19T08:39:17 Z istlemin Election (BOI18_election) C++14
28 / 100
3000 ms 1348 KB
#include<bits/stdc++.h>

using namespace std;

#define rep(i,a,b) for(int i = a; i<int(b);++i)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define trav(a,c) for(auto a: c)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;

int main(){
	cin.sync_with_stdio(false);
    ll n;
    string str;
	cin>>n;
	cin>>str;
    ll q;
    cin>>q;
    rep(i,0,q){
		ll a,b;
		cin>>a>>b;
		a--;
        ll diff = 0;
        vector<bool> nullified(n);
        rep(i,a,b){
            if(str[i]=='C') diff++;
            else diff--;
			if(diff<0){
				diff++;
				nullified[i] = true;
			}
        }
        diff = 0;
        for(int i = b-1;i>=a;i--){
            if(nullified[i]) continue;
            if(str[i]=='C') diff++;
            else diff--;
			if(diff<0){
				diff++;
				nullified[i] = true;
			}
        }
        ll ans = 0;
        rep(i,a,b) ans += nullified[i];
		cout<<ans<<endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 376 KB Output is correct
2 Correct 17 ms 376 KB Output is correct
3 Correct 19 ms 460 KB Output is correct
4 Correct 19 ms 484 KB Output is correct
5 Correct 14 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 376 KB Output is correct
2 Correct 17 ms 376 KB Output is correct
3 Correct 19 ms 460 KB Output is correct
4 Correct 19 ms 484 KB Output is correct
5 Correct 14 ms 508 KB Output is correct
6 Execution timed out 3042 ms 1348 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 376 KB Output is correct
2 Correct 17 ms 376 KB Output is correct
3 Correct 19 ms 460 KB Output is correct
4 Correct 19 ms 484 KB Output is correct
5 Correct 14 ms 508 KB Output is correct
6 Execution timed out 3042 ms 1348 KB Time limit exceeded
7 Halted 0 ms 0 KB -