답안 #67880

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
67880 2018-08-15T11:37:45 Z Good parentrises (BOI18_parentrises) C++11
50 / 100
181 ms 9300 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ff first
#define ss second
#define Maxn 1000009
#define ll long long
#define pb push_back
#define Inf 1000000009
#define ppb() pop_back()
#define pii pair <int , int>
#define mid(x, y) (x + y) / 2
#define all(x) x.begin(),x.end()
#define llInf 1000000000000000009
#define tr(i, c) for(__typeof(c).begin() i = (c).begin() ; i != (c).end() ; i++)
using namespace std;
using namespace __gnu_pbds;
typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> order;

int P, T;

int main () {
	//freopen ("file.in", "r", stdin);
	//freopen ("file.out", "w", stdout);
	
 	//srand ((unsigned) time ( NULL ));
	//int randomNumber = rand() % 10 + 1;

	scanf ("%d%d", &P, &T);
	
	if (P == 1) {
		string s, s1;
		vector <pair <int, char> > v;
		
		for (int i = 1; i <= T; i++) {
			v.clear (), s1.clear(), s.clear();
			
			cin >> s;
			
			s1 = s;
			int sz = s.size();
			
			for (int j = 0; j < sz; j++) {
				if (s[j] == '(')
					v.pb ({j, '('});
				
				else {
					if (v.size() > 0 and v.back().ss == '(')
						s1[v.back().ff] = 'B', s1[j] = 'B', v.ppb ();
						
					else
						v.pb ({j, ')'});	
				}	
			}
			
			for (auto j: v) {
				if (j.ss == '(') {
					for (int k = j.ff + 1; k < sz; k++)	
						if (s[k] == ')' and s1[k] == 'B') {
							s1[k] = 'G', s1[j.ff] = 'R';
							break;
						}		
				}
				
				else {
					for (int k = j.ff - 1; k >= 0; k--) {
						if (s[k] == '(' and s1[k] == 'B') {
							s1[k] = 'G', s1[j.ff] = 'R';
							break;
						}
					}
					
				}
			}		 
			
			bool d = 0;
			for (int j = 0; j < sz; j++)
				if (s1[j] == '(' or s1[j] == ')') {
					d = 1;
					break;
				}
				
			if (d)
				puts ("impossible");
				
			else
				cout << s1 << '\n';
		}
	}	

	return 0;
}

Compilation message

parentrises.cpp: In function 'int main()':
parentrises.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d%d", &P, &T);
  ~~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 2 ms 560 KB Output is correct
4 Correct 3 ms 560 KB Output is correct
5 Correct 2 ms 560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 560 KB Output is correct
2 Correct 3 ms 560 KB Output is correct
3 Correct 2 ms 616 KB Output is correct
4 Correct 3 ms 616 KB Output is correct
5 Correct 3 ms 676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 560 KB Output is correct
2 Correct 3 ms 560 KB Output is correct
3 Correct 2 ms 616 KB Output is correct
4 Correct 3 ms 616 KB Output is correct
5 Correct 3 ms 676 KB Output is correct
6 Correct 2 ms 692 KB Output is correct
7 Correct 3 ms 696 KB Output is correct
8 Correct 3 ms 696 KB Output is correct
9 Correct 3 ms 696 KB Output is correct
10 Correct 3 ms 700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 560 KB Output is correct
2 Correct 3 ms 560 KB Output is correct
3 Correct 2 ms 616 KB Output is correct
4 Correct 3 ms 616 KB Output is correct
5 Correct 3 ms 676 KB Output is correct
6 Correct 2 ms 692 KB Output is correct
7 Correct 3 ms 696 KB Output is correct
8 Correct 3 ms 696 KB Output is correct
9 Correct 3 ms 696 KB Output is correct
10 Correct 3 ms 700 KB Output is correct
11 Correct 5 ms 712 KB Output is correct
12 Correct 4 ms 740 KB Output is correct
13 Correct 2 ms 768 KB Output is correct
14 Correct 4 ms 836 KB Output is correct
15 Correct 4 ms 856 KB Output is correct
16 Correct 26 ms 1248 KB Output is correct
17 Correct 7 ms 1364 KB Output is correct
18 Correct 12 ms 1364 KB Output is correct
19 Correct 8 ms 1564 KB Output is correct
20 Correct 8 ms 1672 KB Output is correct
21 Correct 181 ms 3152 KB Output is correct
22 Correct 58 ms 6404 KB Output is correct
23 Correct 82 ms 6404 KB Output is correct
24 Correct 55 ms 7236 KB Output is correct
25 Correct 87 ms 9300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 9300 KB Unexpected end of file - int32 expected
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 9300 KB Unexpected end of file - int32 expected
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 9300 KB Unexpected end of file - int32 expected