This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
string S, ans;
void main2() {
cin >> S;
int cnt = 0, open = 0;
int mx1 = 0;
int mx2 = 0;
for(int i = 0; i < S.size(); i++) {
if(S[i] == '(') cnt++, open++;
else cnt--;
mx1 = max(mx1, -cnt);
if(-cnt > open) {
cout << "impossible\n";
return;
}
}
cnt = open = 0;
for(int i = (int)S.size() - 1; i >= 0; i--) {
if(S[i] == ')') cnt++, open++;
else cnt--;
mx2 = max(mx2, -cnt);
if(-cnt > open) {
cout << "impossible\n";
return;
}
}
ans.clear();
ans.resize(S.size());
for(int i = 0; i < S.size(); i++) {
if(mx1 && S[i] == '(') ans[i] = 'G', mx1--;
}
for(int i = (int)S.size() - 1; i >= 0; i--) {
if(mx2 && S[i] == ')') ans[i] = 'G', mx2--;
}
int rg = 0;
int bg = 0;
for(int i = 0; i < S.size(); i++) {
if(ans[i] == 'G') {
if(S[i] == '(') rg++, bg++;
else rg--, bg--;
}
else {
if(S[i] == '(') {
if(rg < bg) ans[i] = 'R', rg++;
else ans[i] = 'B', bg++;
}
else {
if(rg < bg) ans[i] = 'B', bg--;
else ans[i] = 'R', rg--;
}
}
}
cout << ans << endl;
}
void main3() {
}
int P, TC;
int main() {
std::ios::sync_with_stdio(false);
cin >> P >> TC;
if(P == 1) {
while(TC--) main2();
}
if(P == 2) {
while(TC--) main3();
}
}
Compilation message (stderr)
parentrises.cpp: In function 'void main2()':
parentrises.cpp:14:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < S.size(); i++) {
~~^~~~~~~~~~
parentrises.cpp:36:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < S.size(); i++) {
~~^~~~~~~~~~
parentrises.cpp:45:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < S.size(); i++) {
~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |