Submission #101787

# Submission time Handle Problem Language Result Execution time Memory
101787 2019-03-20T08:49:42 Z tushar_2658 Election (BOI18_election) C++14
0 / 100
12 ms 384 KB
#include "bits/stdc++.h"
using namespace std;

const int maxn = 7e4 + 5;
int arr[maxn], arr1[maxn], arr2[maxn];
string s;

int get(int l, int r){
	arr1[l] = arr[l];
	int mini = arr1[l];
	for(int i=l+1; i<=r; i++){
		arr1[i] = 0;
		arr1[i] = arr[i] + arr1[i-1];
		mini = min(mini, arr1[i]);
	}
	arr2[r] = arr[r];
	mini = min(mini, arr2[r]);
	for(int i=r-1; i>=l; i--){
		arr2[i] = 0;
		arr2[i] = arr[i] + arr2[i+1];
		mini = min(mini, arr2[i]);
	}return mini;
}

int main(){
	//freopen("in.txt", "r", stdin);
	int n;
	cin>>n;
	cin>>s;
	for(int i=0; i<n; i++){
		if(s[i] == 'C')arr[i] = 1;
		else arr[i] = -1;
	}
	int q;
	cin>>q;
	while(q--){
		int l, r;
		cin>>l>>r;
		cout<<abs(get(l-1, r-1))<<endl;
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -