답안 #198199

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198199 2020-01-25T06:03:07 Z ruler 괄호 문자열 (CEOI16_match) C++14
10 / 100
19 ms 376 KB
// 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 -