답안 #556689

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
556689 2022-05-03T16:13:37 Z Soumya1 괄호 문자열 (CEOI16_match) C++17
10 / 100
0 ms 340 KB
#include <bits/stdc++.h>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
const int mxN = 1e5 + 5;
int to[mxN][26];
string ans;
string s;
bool solve(int l, int r) {
  if (l > r) return true;
  if (l == r) return false;
  if (to[r][s[l] - 'a'] <= l) return false;
  ans[l] = '(', ans[to[r][s[l] - 'a']] = ')';
  bool ok = solve(l + 1, to[r][s[l] - 'a'] - 1);
  ok &= solve(to[r][s[l] - 'a'] + 1, r);
  return ok;
}
void testCase() {
  cin >> s;
  int n = s.size();
  ans = string(n, 'a');
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      to[i][j] = (i == 0 ? -1 : to[i - 1][j]);
    }
    to[i][s[i] - 'a'] = i;
  }
  bool ok = solve(0, n - 1);
  cout << (!ok ? "-1" : ans) << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  testCase();
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -