Submission #848189

#TimeUsernameProblemLanguageResultExecution timeMemory
848189KN200711Election (BOI18_election)C++14
0 / 100
9 ms344 KiB
# include <bits/stdc++.h>
# define fi first
# define se second
using namespace std;

int main() {
	int N;
	string S;
	
	cin>>N;
	cin>>S;
	
	int Q;
	cin>>Q;
	for(int tc = 1;tc<=Q;tc++) {
		int a, b;
		cin>>a>>b;
		if(a > b) swap(a, b);
		a--;
		b--;
		int c = 0, d = 0, e = 0;
		for(int i=a;i<=b;i++) {
			if(S[i] == 'T') {
				if(c == 0) d++;
				else c--;
			} else c++;
		}
		c = 0;
		for(int i=b;i>=a;i--) {
			if(S[i] == 'T') {
				if(c == 0) e++;
				else c--;
			} else c++;
		}
		printf("%d\n", max(d, e));
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...