답안 #129197

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
129197 2019-07-11T20:02:42 Z thanos parentrises (BOI18_parentrises) C++14
22 / 100
93 ms 1272 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();
    }
    for(int i=0; i<s.length(); i++){
      if(vv[i]){
        bool g=false;
        if(s[i]==')'){
          int h=i-1;
          while(h>=0){
            if(s[h]==')' && !v[h]){
              v[h]=true;
              c[h]=1;
              c[i]=2;
              g=true;
              break;
            }
            h--;
          }
        }
        if(s[i]=='('){
          int h=i+1;
          while(h<s.length()){
            if(s[h]=='(' && !v[h]){
              v[h]=true;
              c[h]=1;
              c[i]=2;
              g=true;
              break;
            }
            h++;
          }
        }
        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;
}

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:38:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<s.length(); i++){
                  ~^~~~~~~~~~~
parentrises.cpp:56:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
           while(h<s.length()){
                 ~^~~~~~~~~~~
parentrises.cpp:77:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<s.length(); i++){
                  ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 508 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 2 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 508 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 2 ms 508 KB Output is correct
11 Correct 8 ms 504 KB Output is correct
12 Correct 3 ms 536 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 4 ms 504 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 93 ms 632 KB Output is correct
17 Runtime error 10 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct