답안 #1117740

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1117740 2024-11-24T07:56:28 Z vjudge1 괄호 문자열 (CEOI16_match) C++17
0 / 100
1 ms 336 KB
#include <bits/stdc++.h>
using namespace std;
# define int long long

void solve()
{
  int cnt = 1;
  string s;
  cin >> s;
  vector < char > bra(s.size(), '*');
  vector < int > chk(s.size() , 0);
  for(int i = 0; i < s.size(); i++)
  {
    for(int j = s.size() - 1; j >= 0; j--)
    {
      if(s[i] == s[j] && bra[i] == '*' && bra[j] == '*')
      {
        bra[i] = '(';
        bra[j] = ')';
        chk[i] = cnt;
        chk[j] = cnt;
        cnt++;
        break;
      }
    }
  }
  for(int i = 0; i < bra.size(); i++)
  {
    if(bra[i] == '*')
    {
      cout << -1 << endl;
      return ;
    }
  }
  for(int i = 0; i < s.size(); i++)
  {
    for(int j = i + 1; j < s.size(); j++)
    {
      if(s[i] == s[j] && chk[i] == chk[j])
      {
        if(j - i == 1)
        {
          if(s[i + 1] != s[i])
          {
            cout << -1 << endl;
            return;  
          }  
          else
            continue;
        }
        if(j - i == 0)
        {
          continue;
        }
        int ind1 = -1, ind2 = -1;
        for(int ic = i + 1; ic < j; ic++)
        {
          for(int jc = i + 2; jc < j; jc++)
          {
            if(s[ic] == s[jc])
            {
              ind1 = ic;
              ind2 = jc;
              break;
            }
          }
          if(ind1 == -1 || ind2 == -1)
          {
            cout << -1 << endl;
            return ;
          }
        }
      }
    }
  }
  for(int i = 0; i < bra.size(); i++)
    cout << bra[i] << ' ';
  cout << endl;
}

signed main()
{
  int tt = 1;
  // cin >> tt;
  while(tt--)
    solve();
}

Compilation message

match.cpp: In function 'void solve()':
match.cpp:12:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |   for(int i = 0; i < s.size(); i++)
      |                  ~~^~~~~~~~~~
match.cpp:27:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   for(int i = 0; i < bra.size(); i++)
      |                  ~~^~~~~~~~~~~~
match.cpp:35:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for(int i = 0; i < s.size(); i++)
      |                  ~~^~~~~~~~~~
match.cpp:37:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(int j = i + 1; j < s.size(); j++)
      |                        ~~^~~~~~~~~~
match.cpp:76:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |   for(int i = 0; i < bra.size(); i++)
      |                  ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -