답안 #67836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
67836 2018-08-15T10:50:44 Z Good parentrises (BOI18_parentrises) C++11
0 / 100
3 ms 700 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;
char s[Maxn];

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 s1;
		vector <pair <int, char> > v;
		
		for (int i = 1; i <= T; i++) {
			scanf ("%s", &s);
			v.clear ();
			
			s1 = s;
			int sz = strlen (s);
			
			for (int j = 0; j < sz; j++)	
				s1[j] = '*';
			
			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 = sz - 1; k > j.ff; 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] == '*') {
					d = 1;
					break;
				}
				
			if (d)
				puts ("impossible");
				
			else
				cout << s1 << '\n';
		}
	}	

	return 0;
}

Compilation message

parentrises.cpp: In function 'int main()':
parentrises.cpp:37:19: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[1000009]' [-Wformat=]
    scanf ("%s", &s);
                 ~~^
parentrises.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d%d", &P, &T);
  ~~~~~~^~~~~~~~~~~~~~~~
parentrises.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf ("%s", &s);
    ~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Incorrect 2 ms 600 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 600 KB Output is correct
2 Incorrect 3 ms 652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 600 KB Output is correct
2 Incorrect 3 ms 652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 600 KB Output is correct
2 Incorrect 3 ms 652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 700 KB Unexpected end of file - int32 expected
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 700 KB Unexpected end of file - int32 expected
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 700 KB Unexpected end of file - int32 expected