제출 #129218

#제출 시각아이디문제언어결과실행 시간메모리
129218thanosparentrises (BOI18_parentrises)C++14
22 / 100
1072 ms6264 KiB
#include<iostream>
#include<string>
#include<stack>
using namespace std;
string s;
bool v[1000005],vv[1000005];
int c[1000005];
void initialise(){
  s.clear();
  for(int i=0; i<=1000002; i++){
    v[i]=false;
    vv[i]=false;
    c[i]=0;
  }
}
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;
    initialise(); //c,s,v,vv[]
    stack<int> myst;
    //bool v[10005]={false},vv[100005]={false};
    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){
      continue;
    }
    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;
  }
  return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

parentrises.cpp: In function 'int main()':
parentrises.cpp:31:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<s.length(); i++){
                  ~^~~~~~~~~~~
parentrises.cpp:49:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<s.length(); i++){
                  ~^~~~~~~~~~~
parentrises.cpp:95:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<s.length(); i++){
                  ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...