답안 #90481

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
90481 2018-12-21T20:26:00 Z tincamatei 괄호 문자열 (CEOI16_match) C++14
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>

using namespace std;

int st[100000], top;

bool check(string str, string par) {
  for(int i = 0; i < str.size(); ++i)
    if(par[i] == '(')
      st[top++] = i;
    else if(top > 0 && par[st[top - 1]] == '(' && str[st[top - 1]] == str[i])
      --top;
    else
      return false;

  if(top == 0)
    return true;
  return false;
}

vector<int> poz[26];

int main() {
  string str, par;

  cin >> str;

  for(int i = 0; i < str.size(); ++i)
    poz[str[i] - 'a'].push_back(i);

  par.resize(str.size());

  for(int i = 0; i < 26; ++i) {
    for(int j = 0; j < poz[i].size() / 2; ++j)
      par[poz[i][j]] = '(';
    for(int j = poz[i].size() / 2; j < poz[i].size(); ++j)
      par[poz[i][j]] = ')';
  }

  if(check(str, par))
    cout << par;
  else
    cout << -1;
  return 0;
}

Compilation message

match.cpp: In function 'bool check(std::__cxx11::string, std::__cxx11::string)':
match.cpp:8:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < str.size(); ++i)
                  ~~^~~~~~~~~~~~
match.cpp: In function 'int main()':
match.cpp:28:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < str.size(); ++i)
                  ~~^~~~~~~~~~~~
match.cpp:34:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j = 0; j < poz[i].size() / 2; ++j)
                    ~~^~~~~~~~~~~~~~~~~~~
match.cpp:36:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j = poz[i].size() / 2; j < poz[i].size(); ++j)
                                    ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -