답안 #129221

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
129221 2019-07-11T20:58:12 Z thanos parentrises (BOI18_parentrises) C++14
50 / 100
316 ms 13416 KB
#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;
}

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:83:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int i=0; i<s.length(); i++){
                    ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 252 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 252 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 39 ms 552 KB Output is correct
17 Correct 15 ms 1528 KB Output is correct
18 Correct 13 ms 632 KB Output is correct
19 Correct 14 ms 1016 KB Output is correct
20 Correct 15 ms 1656 KB Output is correct
21 Correct 316 ms 2360 KB Output is correct
22 Correct 143 ms 13288 KB Output is correct
23 Correct 107 ms 3156 KB Output is correct
24 Correct 117 ms 7108 KB Output is correct
25 Correct 136 ms 13416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct