//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
// #include <bits/extc++.h>
using namespace std;
#define debug(s) cout << #s << " = " << s << endl
#define all(v) (v).begin(), (v).end()
#define KeepUnique(v) (v).erase( unique(all(v)), v.end() )
#define MEMSET(a, val) memset(a, val, sizeof (a))
#define PB push_back
#define endl '\n'
typedef long long ll;
inline int myrand(int l, int r) {
int ret = rand(); ret <<= 15; ret ^= rand();
if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
return ret;
}
template <typename F, typename S>
ostream& operator << (ostream& os, const pair< F, S>& p) {
return os<<"(" <<p.first<<", "<<p.second<<")"; }
typedef pair<int, int> ii;
template<typename T> using min_pq =
std::priority_queue<T, vector<T>, greater<T> >;
//int dx[] = {-1, +0, +1, +0};
//int dy[] = {+0, +1, +0, -1};
const int maxn = 1000006;
int matched[maxn], wot[maxn];
string s;
int32_t main () {
// freopen("in", "r", stdin);
int p; cin >> p;
int t; cin >> t;
while(t--) {
cin >> s;
for(int i = 0; i < s.size(); i++)
matched[i] = 0, wot[i] = 0;
stack<int> stk;
for(int i = 0; i < s.size(); i++) {
if(s[i] == '(') stk.emplace(i);
if(s[i] == ')') {
if(stk.size()) {
int top = stk.top();
matched[top] = 1;
matched[i] = 1;
wot[top]++;
wot[i]++;
stk.pop();
}
}
}
int flag = 1;
while(stk.size()) stk.pop();
for(int i = 0; i < s.size(); i++) {
if(matched[i] and s[i] == '(') {
stk.emplace(i);
}
if(!matched[i] and s[i] == ')') {
if(stk.size()) {
int top = stk.top();
stk.pop();
wot[top] += 2;
matched[i] = 1;
wot[i] += 2;
} else {
flag = 0;
break;
}
}
}
while(stk.size()) stk.pop();
for(int i = s.size() - 1; i >= 0; i--) {
if(matched[i] and s[i] == ')') {
stk.emplace(i);
}
if(!matched[i] and s[i] == '(') {
if(stk.size()) {
int top = stk.top();
stk.pop();
wot[top] += 2;
matched[i] = 1;
wot[i] += 2;
} else {
flag = 0;
break;
}
}
}
if(!flag) {
cout << "impossible" << endl;
} else {
string ans;
for(int i = 0; i < s.size(); i++) {
if(wot[i] == 1) ans += "R";
else if(wot[i] == 2) ans += "B";
else ans += "G";
}
cout << ans << endl;
}
}
}
Compilation message
parentrises.cpp: In function 'int myrand(int, int)':
parentrises.cpp:18:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
^~
parentrises.cpp:18:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
^~~
parentrises.cpp: In function 'int32_t main()':
parentrises.cpp:45:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < s.size(); i++)
~~^~~~~~~~~~
parentrises.cpp:48:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < s.size(); i++) {
~~^~~~~~~~~~
parentrises.cpp:63:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < s.size(); i++) {
~~^~~~~~~~~~
parentrises.cpp:102:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < s.size(); i++) {
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
544 KB |
Output is correct |
5 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
700 KB |
Output is correct |
2 |
Correct |
2 ms |
832 KB |
Output is correct |
3 |
Correct |
2 ms |
832 KB |
Output is correct |
4 |
Correct |
3 ms |
832 KB |
Output is correct |
5 |
Correct |
2 ms |
832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
700 KB |
Output is correct |
2 |
Correct |
2 ms |
832 KB |
Output is correct |
3 |
Correct |
2 ms |
832 KB |
Output is correct |
4 |
Correct |
3 ms |
832 KB |
Output is correct |
5 |
Correct |
2 ms |
832 KB |
Output is correct |
6 |
Correct |
2 ms |
832 KB |
Output is correct |
7 |
Correct |
2 ms |
832 KB |
Output is correct |
8 |
Correct |
2 ms |
832 KB |
Output is correct |
9 |
Correct |
3 ms |
832 KB |
Output is correct |
10 |
Correct |
4 ms |
832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
700 KB |
Output is correct |
2 |
Correct |
2 ms |
832 KB |
Output is correct |
3 |
Correct |
2 ms |
832 KB |
Output is correct |
4 |
Correct |
3 ms |
832 KB |
Output is correct |
5 |
Correct |
2 ms |
832 KB |
Output is correct |
6 |
Correct |
2 ms |
832 KB |
Output is correct |
7 |
Correct |
2 ms |
832 KB |
Output is correct |
8 |
Correct |
2 ms |
832 KB |
Output is correct |
9 |
Correct |
3 ms |
832 KB |
Output is correct |
10 |
Correct |
4 ms |
832 KB |
Output is correct |
11 |
Correct |
4 ms |
920 KB |
Output is correct |
12 |
Correct |
3 ms |
952 KB |
Output is correct |
13 |
Correct |
3 ms |
952 KB |
Output is correct |
14 |
Correct |
3 ms |
952 KB |
Output is correct |
15 |
Correct |
3 ms |
1016 KB |
Output is correct |
16 |
Correct |
26 ms |
1044 KB |
Output is correct |
17 |
Correct |
10 ms |
2432 KB |
Output is correct |
18 |
Correct |
9 ms |
2432 KB |
Output is correct |
19 |
Correct |
12 ms |
2432 KB |
Output is correct |
20 |
Correct |
12 ms |
2732 KB |
Output is correct |
21 |
Correct |
192 ms |
3072 KB |
Output is correct |
22 |
Correct |
96 ms |
17156 KB |
Output is correct |
23 |
Correct |
78 ms |
17156 KB |
Output is correct |
24 |
Correct |
101 ms |
17156 KB |
Output is correct |
25 |
Correct |
143 ms |
20044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
20044 KB |
Expected integer, but "G" found |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
20044 KB |
Expected integer, but "G" found |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
20044 KB |
Expected integer, but "G" found |