답안 #314766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
314766 2020-10-21T06:52:51 Z kshitij_sodani Election (BOI18_election) C++14
0 / 100
3 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
#define endl '\n' 


int n;
string s;
int vis[2001];
int pre[2001];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	cin>>s;
	int q;
	cin>>q;
	for(int i=1;i<=n;i++){
		pre[i]=pre[i-1];
		if(s[i-1]=='C'){
			pre[i]-=1;
		}
		else{
			pre[i]+=1;
		}
	//	cout<<pre[i]<<":";
	}
//	cout<<endl;
	while(q--){
		int l,r;
		cin>>l>>r;
		l--;
		r--;
		int co=1;
		int ans2=0;
		for(int i=l;i<=r;i++){
			int cot=max(pre[r+1]-pre[i],0)+max(pre[i+1]-pre[l],0);
			if(pre[r+1]-pre[i]>0 and pre[i+1]-pre[l]>0 and s[i]=='T'){
				cot-=1;
			}
	//		cout<<cot<<":";
			ans2=max(ans2,cot);
		}
//		cout<<endl;
		cout<<ans2<<endl;
		continue;
		/*for(int i=1;i<=n;i++){
			pre[i]=pre[i-1];
			if(s[i-1]=='C'){
				pre[i]-=1;
			}
			else{
				pre[i]+=1;
			}
		//	cout<<pre[i]<<":";
		}
*/
		for(int i=0;i<n;i++){
			vis[i]=0;
		}
		
		for(int i=l;i<=r;i++){
		//	cout<<pre[i+1]<<":"<<pre[l]<<endl;
			if(pre[i+1]-pre[l]==co){
				vis[i]=1;
				co+=1;
			//	cout<<i<<":";
			//	cout<<pre[i+1]<<":"<<pre[l]<<endl;
			}
		}
		for(int i=1;i<=n;i++){
			pre[i]=pre[i-1];
			if(vis[i]!=1){
				if(s[i-1]=='C'){
					pre[i]-=1;
				}
				else{
					pre[i]+=1;
				}
			}
		//	cout<<pre[i]<<":";
		}
	//	cout<<endl;
		int ans=co-1;
		co=1;
		for(int i=r;i>=l;i--){
			if(vis[i]){
				continue;
			}
			if(pre[r+1]-pre[i]==co){
				vis[i]=1;
				co+=1;
			//	cout<<i<<":";
			}
		}
	//	cout<<endl;
		ans=max(ans,co-1);
		ans=0;
		for(int i=0;i<n;i++){
			ans+=vis[i];
		}
		cout<<ans<<endl;





	}










	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -