Submission #74126

# Submission time Handle Problem Language Result Execution time Memory
74126 2018-08-30T07:32:29 Z jiajunlee parentrises (BOI18_parentrises) C++14
0 / 100
2 ms 464 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;
string nono = {"impossible"};
 
int main(void)
{
  cin >> type >> t;
  if(type == 1)
  {
    for(LL i0 = 0; i0 < t; i0++)
    {
      //cout << "Ya" << endl;
      string input;
      cin >> input;
      //cout << "YAYA" << endl;
      LL SIZE = input.size();
      deque<pair<char, LL> > parent = {};
      char ans[SIZE+5] = {};
      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:55:11: warning: 'j' may be used uninitialized in this function [-Wmaybe-uninitialized]
           if(SIZE <= j)
           ^~
parentrises.cpp:80:11: warning: 'i' may be used uninitialized in this function [-Wmaybe-uninitialized]
           if(i < 0)
           ^~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 372 KB Output is correct
2 Incorrect 2 ms 448 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 372 KB Output is correct
2 Incorrect 2 ms 448 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 372 KB Output is correct
2 Incorrect 2 ms 448 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 464 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 464 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 464 KB Unexpected end of file - int32 expected