Submission #1117888

# Submission time Handle Problem Language Result Execution time Memory
1117888 2024-11-24T09:17:57 Z vjudge1 Match (CEOI16_match) C++17
0 / 100
7 ms 336 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);
  }
  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 7 ms 336 KB Output is correct
3 Incorrect 4 ms 336 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 7 ms 336 KB Output is correct
3 Incorrect 4 ms 336 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 7 ms 336 KB Output is correct
3 Incorrect 4 ms 336 KB Output isn't correct
4 Halted 0 ms 0 KB -