Submission #321081

#TimeUsernameProblemLanguageResultExecution timeMemory
321081kapselElection (BOI18_election)C++17
28 / 100
3057 ms1256 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...