Submission #476129

# Submission time Handle Problem Language Result Execution time Memory
476129 2021-09-24T21:46:13 Z elgamalsalman Match (CEOI16_match) C++14
10 / 100
0 ms 316 KB
#include <bits/stdc++.h>

using namespace std;

int n;
string s;

bool validate(int l, int r) {
  //cerr << "// validate(" << l << ", " << r << ")\n";
  if (r < l) return 1;
  int ind = 0;
  for (int i = l + 1; i <= r; i++) {
    if (s[l] == s[i]) ind = i;
  }
  if (!ind) return 0;
  s[l] = '(';
  s[ind] = ')';
  return (validate(l + 1, ind - 1) && validate(ind + 1, r));
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  //freopen("match.in", "r", stdin);
  //freopen("match.out", "w", stdout);
  
  cin >> s;
  n = (int)s.size();
  if (!validate(0, n - 1)) cout << "-1\n";
  else cout << s << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 0 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 0 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -