Submission #638820

# Submission time Handle Problem Language Result Execution time Memory
638820 2022-09-07T14:52:21 Z georgievskiy Election (BOI18_election) C++17
28 / 100
3000 ms 1444 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
	int n;
	string s;
	cin >> n >> s;
	vector<int> c(n, 0);
	int q;
	cin >> q;
	while (q--) {
		int l, r;
		cin >> l >> r;
		l--;
		fill(c.begin() + l, c.begin() + r, 0);
		int b = 0;
		for (int i = l; i < r; i++) {
			if (s[i] == 'C') {
				b++;
			} else {
				b--;
				if (b < 0) {
					b = 0;
					c[i] = 1;
				}
			}
		}
		b = 0;
		for (int i = r - 1; i >= l; i--) {
			if (s[i] == 'C') {
				b++;
			} else if (!c[i]) {
				b--;
				if (b < 0) {
					b = 0;
					c[i] = 1;
				}
			}
		}
		int ans = count(c.begin() + l, c.begin() + r, 1);
		cout << ans << "\n";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 340 KB Output is correct
2 Correct 11 ms 340 KB Output is correct
3 Correct 11 ms 340 KB Output is correct
4 Correct 10 ms 344 KB Output is correct
5 Correct 7 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 340 KB Output is correct
2 Correct 11 ms 340 KB Output is correct
3 Correct 11 ms 340 KB Output is correct
4 Correct 10 ms 344 KB Output is correct
5 Correct 7 ms 340 KB Output is correct
6 Execution timed out 3068 ms 1444 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 340 KB Output is correct
2 Correct 11 ms 340 KB Output is correct
3 Correct 11 ms 340 KB Output is correct
4 Correct 10 ms 344 KB Output is correct
5 Correct 7 ms 340 KB Output is correct
6 Execution timed out 3068 ms 1444 KB Time limit exceeded
7 Halted 0 ms 0 KB -