// IOI 2021
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
////////////////////////////////////////////////////////////////////
const int N = 1e4 + 5;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
string s; cin >> s;
int n = sz(s);
vector<string> v;
for (int mask = 0; mask < (1 << n); mask++) {
if (2 * __builtin_popcount(mask) != n) continue;
stack<int> st;
bool flag = true;
for (int i = 0; i < n; i++) {
if ((mask >> i) & 1) st.push(i);
else if (st.empty()) flag = false;
else {
int t = st.top(); st.pop();
flag &= s[i] == s[t];
}
}
flag &= st.empty();
if (!flag) continue;
string t = "";
for (int i = 0; i < n; i++) if ((mask >> i) & 1) t += '('; else t += ')';
v.push_back(t);
}
if (v.empty()) die(-1);
sort(all(v));
cout << v[0] << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
12 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
12 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Incorrect |
19 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
12 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Incorrect |
19 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |