답안 #60910

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
60910 2018-07-25T00:54:26 Z spencercompton Election (BOI18_election) C++14
0 / 100
20 ms 248 KB
#include <bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int q;
	cin >> q;
	for(int i = 0; i<q; i++){
		bool use[n];
		for(int j = 0; j<n; j++){
			use[j] = true;
		}
		int cur = 0;
		int l, r;
		cin >> l >> r;
		l--;
		r--;
		int ans = 0;
		vector<int> l1;
		for(int j = l; j<=r; j++){
			if(s[j]=='T' && cur==0){
				// ans++;
				l1.push_back(j);
				// use[j] = false;
			}
			else if(s[j]=='T'){
				cur--;
			}
			else{
				cur++;
			}
		}
		cur = 0;
		vector<int> l2;
		for(int j = r; j>=l; j--){
			if(s[j]=='T' && cur==0){
				// use[j] = false;
				l2.push_back(j);
				// ans++;
			}
			else if(s[j]=='T'){
				cur--;
			}
			else if(s[j]=='C'){
				cur++;
			}
		}
		if(l1.size()==0 || l2.size()==0){
			ans = l1.size() + l2.size();
		}
		else{
			int b = l1[l1.size()-1];
			int a = l2[l2.size()-1];
			if(a > b){
				ans = l1.size() + l2.size();
			}
			else{
				int m1 = 0;
				int m2 = 0;
				for(int j = 0; j<l1.size(); j++){
					if(l1[j]>=a && l1[j]<=b){
						m1++;
					}
				}
				for(int j = 0; j<l2.size(); j++){
					if(l2[j]>=a && l2[j]<=b){
						m2++;
					}
				}
				ans = l1.size()-m1 + l2.size()-m2 + max(m1,m2);
			}
		}
		cout << ans << endl;
	}
}

Compilation message

election.cpp: In function 'int main()':
election.cpp:65:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j = 0; j<l1.size(); j++){
                    ~^~~~~~~~~~
election.cpp:70:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j = 0; j<l2.size(); j++){
                    ~^~~~~~~~~~
election.cpp:14:8: warning: variable 'use' set but not used [-Wunused-but-set-variable]
   bool use[n];
        ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -