답안 #571440

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
571440 2022-06-02T08:33:16 Z duytuandao21 Election (BOI18_election) C++14
28 / 100
3000 ms 1144 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 2e6+7;
int n,q;
string s;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n>>s>>q;
	while(q--) {
		int l,r;
		cin>>l>>r; l--; r--;
		string t = s;
		int cnt1 = 0, cnt2 = 0, res = 0;
		vector<bool> ok(n+1,0);
		for(int i=l;i<=r;i++) {
			if(t[i] == 'C') cnt1++; else cnt1--;
			if(cnt1 < 0) {
				t[i] = 'C';
				ok[i] = 1;
				res++;
				cnt1++;
			}
		}
		//for(int i=0;i<n;i++) cout<<t[i]<<" "; cout<<cnt1; cout<<'\n';
		for(int i=r;i>=l;i--) {
			if(ok[i]==1) continue;
			if(t[i] == 'C') cnt2++; else cnt2--;
			if(cnt2 < 0) {
				t[i] = 'C';
				res++;
				cnt2++;
			}
		}

		cout<<res<<'\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 212 KB Output is correct
2 Correct 7 ms 340 KB Output is correct
3 Correct 6 ms 352 KB Output is correct
4 Correct 7 ms 336 KB Output is correct
5 Correct 5 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 212 KB Output is correct
2 Correct 7 ms 340 KB Output is correct
3 Correct 6 ms 352 KB Output is correct
4 Correct 7 ms 336 KB Output is correct
5 Correct 5 ms 340 KB Output is correct
6 Execution timed out 3059 ms 1144 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 212 KB Output is correct
2 Correct 7 ms 340 KB Output is correct
3 Correct 6 ms 352 KB Output is correct
4 Correct 7 ms 336 KB Output is correct
5 Correct 5 ms 340 KB Output is correct
6 Execution timed out 3059 ms 1144 KB Time limit exceeded
7 Halted 0 ms 0 KB -