Submission #1294082

#TimeUsernameProblemLanguageResultExecution timeMemory
1294082ayazMatch (CEOI16_match)C++20
37 / 100
2095 ms632 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
#define ll long long
#define ui unsigned int
#define pb push_back
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
#define isz(x) (int)(x.size())
#define vi vector<int> 
#define ost tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update>
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int sz = 1e6, inf = 1e9;
const ll mod = 998244353, INF = 1e18;
void solve(int tc) {
  string s;
  cin >> s;
  int n = isz(s);
  auto check = [&](int idx, stack<char> st) -> bool {
    for (int i = idx; i < isz(s); i++) {
      if (st.empty() || s[i] != st.top()) 
        st.push(s[i]);
      else st.pop();
    }
    return (st.empty());
  };
  stack<char> t;
  string ans;
  ans.resize(n);
  for (int i = 0; i < n; i++) {
    t.push(s[i]);
    ans[i] = '(';
    if (check(i+1, t))
      continue;
    t.pop();
    if (isz(t) == 0) {
      cout << "-1\n";
      return;
    }
    t.pop();
    ans[i] = ')';
    if (check(i+1, t))
      continue;
  }
  cout << ans << '\n';
}
void precompute() {}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
  // freopen("err.log", "w", stderr);
#endif
  precompute();
  int t = 1;
  // cin >> t;
  for (int tc = 1; tc <= t; tc++) solve(tc);
  return 0;    
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...