답안 #244097

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
244097 2020-07-02T15:11:22 Z tonowak 괄호 문자열 (CEOI16_match) C++14
0 / 100
19 ms 384 KB
#include <bits/stdc++.h> // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using LL = long long;    // Poland
#define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
#define REP(i, n) FOR(i, 0, (n) - 1)
template<class T> int size(T &&x) {
	return int(x.size());
}
template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) {
	return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
	out << '{';
	for(auto it = x.begin(); it != x.end(); ++it)
		out << *it << (it == prev(x.end()) ? "" : ", ");
	return out << '}';
}
void dump() {}
template<class T, class... Args> void dump(T &&x, Args... args) {
	cerr << x << ";  ";
	dump(args...);
}
#ifdef DEBUG
  struct Nl{~Nl(){cerr << '\n';}};
# define debug(x...) cerr << (#x != "" ? #x ":  " : ""), dump(x), Nl(), cerr
#else
# define debug(...) 0 && cerr
#endif
mt19937_64 rng(0);
int rd(int l, int r) {
	return uniform_int_distribution<int>(l, r)(rng);
}
// end of templates

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	string s;
	cin >> s;
	const int n = size(s);
	int answer = -1;
	REP(mask, 1 << n) {
		auto consider = [&] {
			vector<int> open;
			REP(i, n)
				if((mask >> i) & 1) {
					if(size(open) == 0)
						return;
					int l = open.back();
					open.pop_back();
					if(s[l] != s[i])
						return;
				}
				else
					open.emplace_back(i);
			if(size(open))
				return;
			debug(mask);
			answer = max(answer, mask);
		};
		consider();
	}

	if(answer == -1)
		cout << "-1\n";
	else {
		REP(i, n)
			if((answer >> i) & 1)
				cout << ')';
			else
				cout << '(';
		cout << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 19 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 19 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 19 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -