#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 = 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] == '(' 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);
~~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
488 KB |
Output is correct |
3 |
Incorrect |
2 ms |
488 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
488 KB |
Output is correct |
2 |
Incorrect |
2 ms |
520 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
488 KB |
Output is correct |
2 |
Incorrect |
2 ms |
520 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
488 KB |
Output is correct |
2 |
Incorrect |
2 ms |
520 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
580 KB |
Unexpected end of file - int32 expected |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
580 KB |
Unexpected end of file - int32 expected |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
580 KB |
Unexpected end of file - int32 expected |