# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
129221 | thanos | parentrises (BOI18_parentrises) | C++14 | 316 ms | 13416 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<string>
#include<stack>
using namespace std;
string s;
int c[1000005];
bool v[1000005],vv[1000005];
int main(){
int P;
cin>>P;
if(P==2){
cout<<0<<endl;
return 0;
}
int T;
cin>>T;
for(int k=0; k<T; k++){
bool f=true;
stack<int> myst;
cin>>s;
for(int i=0; i<s.length(); i++){
if(s[i]=='('){
myst.push(i);
}
else{
if(!myst.empty()){
myst.pop();
}
else{
v[i]=vv[i]=true;
}
}
}
while(!myst.empty()){
v[myst.top()]=vv[myst.top()]=true;
myst.pop();
}
stack<int> tl,tr;
for(int i=0; i<s.length(); i++){
bool g=true;
if(vv[i]){
if(s[i]==')'){
g=false;
if(!tl.empty()){
v[tl.top()]=true;
c[tl.top()]=1;
c[i]=2;
g=true;
tl.pop();
}
}
}
else if(s[i]==')'){
tl.push(i);
}
if(!g){
cout<<"impossible"<<endl;
f=false;;
break;
}
if(vv[s.length()-i-1]){
if(s[s.length()-i-1]=='('){
g=false;
if(!tr.empty()){
v[tr.top()]=true;
c[tr.top()]=1;
c[s.length()-i-1]=2;
g=true;
tr.pop();
}
}
}
else if(s[s.length()-i-1]=='('){
tr.push(s.length()-i-1);
}
if(!g){
cout<<"impossible"<<endl;
f=false;
break;
}
}
if(f){
for(int i=0; i<s.length(); i++){
if(c[i]==0){
cout<<"G";
}
else if(c[i]==1){
cout<<"B";
}
else{
cout<<"R";
}
}
cout<<endl;
}
int l=s.length();
s.clear();
for(int i=0; i<=l; i++){
c[i]=0;
vv[i]=v[i]=false;
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |