Submission #74124

# Submission time Handle Problem Language Result Execution time Memory
74124 2018-08-30T07:27:51 Z jiajunlee parentrises (BOI18_parentrises) C++14
0 / 100
2 ms 596 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)
  {
    for(LL i0 = 0; i0 < t; i0++)
    {
      //cout << "Ya" << endl;
      cin >> input;
      //cout << "YAYA" << 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: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 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 508 KB Output is correct
2 Incorrect 2 ms 596 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 508 KB Output is correct
2 Incorrect 2 ms 596 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 508 KB Output is correct
2 Incorrect 2 ms 596 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 596 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 596 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 596 KB Unexpected end of file - int32 expected