답안 #74128

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
74128 2018-08-30T07:37:31 Z haitun Election (BOI18_election) C++14
28 / 100
3000 ms 2840 KB
#include <bits/stdc++.h>
//#include "functions.h"
#define FOR(x,y) for(int x = 0; x < y; x++)
#define ALLR(x) x.begin(),x.end()
#define con continue
#define ll long long
#define LINF LLONG_MAX
#define INF INT_MAX
#define pii pair<int,int>
#define vi vector <int>
#define pb push_back
#define F first
#define S second
#define len(x) x.length()
#define sz(x) x.size()
#define SEE(v)	for(auto x : v)	cout << x << " "; cout << endl;
using namespace std;

int main(){
	
	if(fopen("test.txt","r"))	freopen("test.txt","r",stdin);
	
	int n;
	cin >> n;
	string s;
	cin >> s;
	
	int q;
	cin >> q;
	vector <pii> sc(q);
	FOR(j, q)	cin >> sc[j].F >> sc[j].S;
	
	FOR(j, q)
	{
		int l = sc[j].F, r = sc[j].S;
		string ss = s.substr(l - 1, r - l + 1);
		
		//cout << ss << endl;
		
		vector <bool> nulled(ss.length(), 0);
		int cnt1 = 0, cnt2 = 0, ans = 0;
		FOR(k, ss.length())
		{
			if(ss[k] == 'C')	cnt1++;
			else				cnt2++;
			
			if(cnt2 > cnt1)
			{
				cnt2--;
				nulled[k] = true;
			}
		}
		
		cnt1 = cnt2 = 0;
		
		for(int k = ss.length() - 1; k >= 0; k--)
		{
			if(nulled[k])	con;
			if(ss[k] == 'C')	cnt1++;
			else				cnt2++;
			
			if(cnt2 > cnt1)
			{
				cnt2--;
				nulled[k] = true;
			}
		}
		
		
		FOR(k, nulled.size())
		{
			if(nulled[k])	ans++;
		}
		cout << ans << endl;
	}
}

Compilation message

election.cpp: In function 'int main()':
election.cpp:3:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define FOR(x,y) for(int x = 0; x < y; x++)
election.cpp:42:7:
   FOR(k, ss.length())
       ~~~~~~~~~~~~~~               
election.cpp:42:3: note: in expansion of macro 'FOR'
   FOR(k, ss.length())
   ^~~
election.cpp:3:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define FOR(x,y) for(int x = 0; x < y; x++)
election.cpp:70:7:
   FOR(k, nulled.size())
       ~~~~~~~~~~~~~~~~             
election.cpp:70:3: note: in expansion of macro 'FOR'
   FOR(k, nulled.size())
   ^~~
election.cpp:21:35: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  if(fopen("test.txt","r")) freopen("test.txt","r",stdin);
                            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 376 KB Output is correct
2 Correct 20 ms 500 KB Output is correct
3 Correct 21 ms 652 KB Output is correct
4 Correct 16 ms 808 KB Output is correct
5 Correct 13 ms 808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 376 KB Output is correct
2 Correct 20 ms 500 KB Output is correct
3 Correct 21 ms 652 KB Output is correct
4 Correct 16 ms 808 KB Output is correct
5 Correct 13 ms 808 KB Output is correct
6 Execution timed out 3036 ms 2840 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 376 KB Output is correct
2 Correct 20 ms 500 KB Output is correct
3 Correct 21 ms 652 KB Output is correct
4 Correct 16 ms 808 KB Output is correct
5 Correct 13 ms 808 KB Output is correct
6 Execution timed out 3036 ms 2840 KB Time limit exceeded
7 Halted 0 ms 0 KB -