답안 #74123

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
74123 2018-08-30T07:06:48 Z jiajunlee parentrises (BOI18_parentrises) C++14
0 / 100
1000 ms 424 KB
#include <iostream>
#include <cstring>
#include <stack>
#include <deque>

using namespace std;


typedef long long LL;

const LL MAXN = 1000 * 1005; 
const LL MOD = (1000 * 1000 * 1000) + 7;

LL type, t;
LL SIZE;
string input, nono = {"impossible"};

int main(void)
{
  cin >> type >> t;
  if(type == 1)
  {
    string temp;
    getline(cin, temp);
    for(LL i0 = 0; i0 < t; i0++)
    {
      getline(cin, input);
      //cout << input << endl;
      SIZE = input.size();
      deque<pair<char, LL> > parent = {};
      char ans[SIZE] = {};
      bool GG = false;
      for(LL idx = 0; idx < SIZE; idx++)
      {
        if(!parent.empty() && parent.back().first == '(' && input[idx] == ')')
        {
          ans[parent.back().second] = 'G';
          ans[idx] = 'G';
          parent.pop_back();
        }else parent.push_back(make_pair(input[idx], idx));
      }
      //cout << "normal" << endl;
      LL i, j;
      if(!parent.empty() )
      {
        i = parent.front().second-1;
        j = parent.back().second+1;
      }
      while(!parent.empty() )
      {
        //i = min(i, parent.back().second-1);
        //j = max(j, parent.back().second+1);
        if(GG)break;
        if(parent.back().first == '(')
        {
          if(SIZE <= j)
          {
            GG = true;
            break;
          }
          while(j < SIZE)
          {
            if(input[j] == '(' && ans[j] == 'G')
            {
              ans[j] = 'R';
              ans[parent.back().second] = 'B';
              parent.pop_back();
              j++;
              break;
            }
            j++;
            if(SIZE <= j)
            {
              GG = true;
              break;
            }
          }
        }
        if(parent.front().first == ')')
        {
          if(i < 0)
          {
            GG = true;
            break;
          }
          while(0 <= i)
          {
            if(input[i] == ')' && ans[i] == 'G')
            {
              ans[i] = 'R';
              ans[parent.front().second] = 'B';
              parent.pop_front();
              i--;
              break;
            }
            i--;
            if(i < 0)
            {
              GG = true;
              break;
            }
          }
        }
      }
      //cout << "FIN" << endl;
      if(GG || !parent.empty())cout << nono << endl;
      else 
      {
        for(LL idx = 0; idx < SIZE; idx++)
        {
          cout << ans[idx];
        }
        cout << endl;
      }
    }
  }else
  {

  }
  return 0;
}

Compilation message

parentrises.cpp: In function 'int main()':
parentrises.cpp:56:11: warning: 'j' may be used uninitialized in this function [-Wmaybe-uninitialized]
           if(SIZE <= j)
           ^~
parentrises.cpp:81:11: warning: 'i' may be used uninitialized in this function [-Wmaybe-uninitialized]
           if(i < 0)
           ^~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1071 ms 376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1078 ms 380 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1078 ms 380 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1078 ms 380 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 424 KB Unexpected end of file - int32 expected
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 424 KB Unexpected end of file - int32 expected
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 424 KB Unexpected end of file - int32 expected