Submission #556687

# Submission time Handle Problem Language Result Execution time Memory
556687 2022-05-03T16:07:49 Z Soumya1 Match (CEOI16_match) C++17
10 / 100
1 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();
  s = s;
  ans = string(n, 'a');
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) to[i][j] = 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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -