Submission #1117891

# Submission time Handle Problem Language Result Execution time Memory
1117891 2024-11-24T09:18:55 Z vjudge1 Match (CEOI16_match) C++17
10 / 100
10 ms 508 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define inf 0x3F3F3F3F3F3F3F3F

const int MXN = 3e6 + 5;
const int mod = 998244353;

void _()
{
  string s;
  cin >> s;
  int n = s.length();
  if (n & 1) 
  {
    cout << -1 << '\n';
    return;
  }
  string res(n, ')');
  for (int msk = 0; msk < (1 << n); msk++)
  {
    if (__builtin_popcount(msk) != n / 2) continue;
    string nw;
    for (int i = 0; i < n; i++)
    {
      if (msk >> i & 1) nw.push_back(')');
      else nw.push_back('(');
    }
    int f = 1;
    vector<int> v;
    for (int i = 0; i < n; i++)
    {
      if (nw[i] == ')' && v.empty())
      {
        f = 0;
        break;
      }
      if (nw[i] == ')' && s[v.back()] != s[i]) 
      {
        f = 0;
        break;
      } 
      if (nw[i] == ')') v.pop_back();
      else v.push_back(i);
    }
    if (f) res = min(res, nw);
  }
  if (res[0] == ')') cout << -1 << '\n';
  else cout << res << '\n';
}

signed main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  // cin >> t;
  while (t--) _();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 8 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 8 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Incorrect 10 ms 508 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 8 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Incorrect 10 ms 508 KB Output isn't correct
5 Halted 0 ms 0 KB -