#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;
}
Compilation message
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 time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
424 KB |
Output is correct |
3 |
Correct |
2 ms |
440 KB |
Output is correct |
4 |
Correct |
159 ms |
548 KB |
Output is correct |
5 |
Correct |
128 ms |
688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1067 ms |
688 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1067 ms |
688 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1067 ms |
688 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
688 KB |
Unexpected end of file - int32 expected |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
688 KB |
Unexpected end of file - int32 expected |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
688 KB |
Unexpected end of file - int32 expected |