Submission #321081

# Submission time Handle Problem Language Result Execution time Memory
321081 2020-11-10T22:02:30 Z kapsel Election (BOI18_election) C++17
28 / 100
3000 ms 1256 KB
#include <bits/stdc++.h>

using namespace std;

#define LL long long
#define ULL unsigned LL
#define LD long double
#define debug(x) cerr << #x << " " << x << endl;

/*
 * Rozwiazanie brutalne, O(n*q)
 * 
 */

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, q;
	string s;
	cin>>n>>s>>q;
	int a, b;
	while(q--) {
		cin>>a>>b; a--; b--;
		vector<bool> czy(n, 0);
		int ob = 0;
		int ans = 0;
		for(int i=a; i<=b; i++) {
			ob += (s[i] == 'C' ? 1 : -1);
			if(ob < 0) {
				ans++;
				ob++;
				czy[i] = 1;
			}	
		}
		ob = 0;
		for(int i=b; i>=a; i--) {
			if(czy[i])
				continue;
			ob += (s[i] == 'C' ? 1 : -1);
			if(ob < 0) {
				ans++;
				ob++;
			}
		}
		cout<<ans<<"\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 364 KB Output is correct
2 Correct 7 ms 364 KB Output is correct
3 Correct 6 ms 364 KB Output is correct
4 Correct 6 ms 364 KB Output is correct
5 Correct 4 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 364 KB Output is correct
2 Correct 7 ms 364 KB Output is correct
3 Correct 6 ms 364 KB Output is correct
4 Correct 6 ms 364 KB Output is correct
5 Correct 4 ms 364 KB Output is correct
6 Execution timed out 3057 ms 1256 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 364 KB Output is correct
2 Correct 7 ms 364 KB Output is correct
3 Correct 6 ms 364 KB Output is correct
4 Correct 6 ms 364 KB Output is correct
5 Correct 4 ms 364 KB Output is correct
6 Execution timed out 3057 ms 1256 KB Time limit exceeded
7 Halted 0 ms 0 KB -