Submission #129206

# Submission time Handle Problem Language Result Execution time Memory
129206 2019-07-11T20:31:02 Z thanos parentrises (BOI18_parentrises) C++14
0 / 100
2 ms 504 KB
#include<iostream>
#include<string>
#include<stack>
using namespace std;
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;
    string s;
    int c[10005]={0};
    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++){
      if(vv[i]){
        bool g=true;
        if(s[i]==')'){
          g=false;
          if(!tl.empty()){
            v[tl.top()]=true;
            c[tl.top()]=1;
            c[i]=2;
            g=true;
            tl.pop();
          }
        }
        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();
          }
        }
        if(!g){
          cout<<"impossible"<<endl;
          f=false;
          break;
        }
      }
      else{
        if(s[i]==')'){
          tl.push(i);
        }
        if(s[s.length()-i-1]=='('){
          tr.push(s.length()-i-1);
        }
      }
    }
    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;
}

Compilation message

parentrises.cpp: In function 'int main()':
parentrises.cpp:21:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<s.length(); i++){
                  ~^~~~~~~~~~~
parentrises.cpp:39:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<s.length(); i++){
                  ~^~~~~~~~~~~
parentrises.cpp:80:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<s.length(); i++){
                  ~^~~~~~~~~~~
parentrises.cpp:19:10: warning: variable 'v' set but not used [-Wunused-but-set-variable]
     bool v[10005]={false},vv[100005]={false};
          ^
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 504 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 504 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 504 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct