제출 #67871

#제출 시각아이디문제언어결과실행 시간메모리
67871Goodparentrises (BOI18_parentrises)C++11
5 / 100
1067 ms688 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ff first
#define ss second
#define Maxn 100009
#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;

bool d;

int P, T;
string s, s1, ans;

void func (int pos, int sz) {
	if (pos == sz) {
		int a = 0, b = 0;
		for (int i = 0; i < sz; i++) {
			if (s[i] == '(') {
				if (s1[i] == 'B')
					a ++;
				else if (s1[i] == 'R')
					b ++;
				else
					a ++, b ++;		
			}
			else {
				if (s1[i] == 'B')
					a --;
				else if (s1[i] == 'R')
					b --;
				else
					a --, b --;
				
				if (a < 0 or b < 0)
					break;			
			}
			
		}
		if (a == 0 and b == 0) {
			d = 1;
			if (ans[0] == '(')
				ans = s1;
		}	
		return;	
	}
	
	s1[pos] = 'R';
	func (pos + 1, sz);
	s1[pos] = 'B';
	func (pos + 1, sz);
	s1[pos] = 'G';
	func (pos + 1, sz);
}

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) {
		for (int i = 1; i <= T; i++) {
			d = 0;
			cin >> s;
			
			int sz = s.size();
			s1.clear();
			
			ans = s;
			s1 = s;
			
			func (0, sz);
			if (d)
				cout << ans << '\n';
				
			else
				puts ("impossible");	
		}
	}

	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

parentrises.cpp: In function 'int main()':
parentrises.cpp:73:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d%d", &P, &T);
  ~~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...