이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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();
}
}
컴파일 시 표준 에러 (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... |