Submission #861390

# Submission time Handle Problem Language Result Execution time Memory
861390 2023-10-16T05:14:10 Z maks007 Election (BOI18_election) C++14
28 / 100
3000 ms 1128 KB
#include "bits/stdc++.h"

using namespace std;

#define int long long

signed main () {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	string str;
	cin >> str;
	int q;
	cin >> q;
	while(q --) {
		int l, r;
		cin >> l >> r;
		l --, r --;
		int bal = 0;
		set <int> s1, s2;
		for(int i = l; i <= r; i ++) {
			if(str[i] == 'C') bal ++;
			else if(bal == 0) {
				s1.insert(i);
			}else bal --;
		}
		 bal = 0;
		for(int i = r; i >= l; i --) {
			if(s1.count(i)) continue;
			if(str[i] == 'C') bal ++;
			else if(bal == 0) {
				s2.insert(i);
			}else bal --;
		}
		for(auto i : s2) s1.insert(i);
		cout << s1.size() << "\n";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 344 KB Output is correct
2 Correct 17 ms 488 KB Output is correct
3 Correct 8 ms 488 KB Output is correct
4 Correct 46 ms 488 KB Output is correct
5 Correct 24 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 344 KB Output is correct
2 Correct 17 ms 488 KB Output is correct
3 Correct 8 ms 488 KB Output is correct
4 Correct 46 ms 488 KB Output is correct
5 Correct 24 ms 348 KB Output is correct
6 Execution timed out 3069 ms 1128 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 344 KB Output is correct
2 Correct 17 ms 488 KB Output is correct
3 Correct 8 ms 488 KB Output is correct
4 Correct 46 ms 488 KB Output is correct
5 Correct 24 ms 348 KB Output is correct
6 Execution timed out 3069 ms 1128 KB Time limit exceeded
7 Halted 0 ms 0 KB -