답안 #361974

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
361974 2021-02-01T13:14:39 Z kshitij_sodani Election (BOI18_election) C++14
28 / 100
3000 ms 2912 KB
//#pragma GCC optimize("Ofast,unroll-loops")
#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;
int it[500001];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	string s;
	cin>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='T'){
			it[i]=-1;
		}
		else{
			it[i]=1;
		}
		//cout<<it[i]<<",";
	}
	//cout<<endl;
	int q;
	cin>>q;
	while(q--){
		int l,r;
		cin>>l>>r;
		l--;
		r--;
		int su=0;
		vector<int> kk;
		for(int i=l;i<=r;i++){
			kk.pb(it[i]);
		}
	/*	for(auto j:kk){
			cout<<j<<",";
		}
		cout<<endl;*/
		int ans=0;
		for(int i=0;i<kk.size();i++){
			su+=kk[i];
			if(su<0){
				su-=kk[i];
				kk[i]=0;
			//	su+=kk[i];
				ans++;
			}
		}
		su=0;
		for(int i=kk.size()-1;i>=0;i--){
			su+=kk[i];
			if(su<0){
				su-=kk[i];
				kk[i]=0;
			//	su+=kk[i];
				ans++;
			}
		}
	/*	for(auto j:kk){
			cout<<j<<",";
		}
		cout<<endl;*/
		cout<<ans<<endl;

	}



 
	return 0;
}

Compilation message

election.cpp: In function 'int main()':
election.cpp:47:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for(int i=0;i<kk.size();i++){
      |               ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 364 KB Output is correct
2 Correct 5 ms 364 KB Output is correct
3 Correct 5 ms 364 KB Output is correct
4 Correct 6 ms 364 KB Output is correct
5 Correct 5 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 364 KB Output is correct
2 Correct 5 ms 364 KB Output is correct
3 Correct 5 ms 364 KB Output is correct
4 Correct 6 ms 364 KB Output is correct
5 Correct 5 ms 364 KB Output is correct
6 Execution timed out 3090 ms 2912 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 364 KB Output is correct
2 Correct 5 ms 364 KB Output is correct
3 Correct 5 ms 364 KB Output is correct
4 Correct 6 ms 364 KB Output is correct
5 Correct 5 ms 364 KB Output is correct
6 Execution timed out 3090 ms 2912 KB Time limit exceeded
7 Halted 0 ms 0 KB -