답안 #1117622

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1117622 2024-11-24T06:48:28 Z vjudge1 괄호 문자열 (CEOI16_match) C++17
0 / 100
1 ms 336 KB
#include <bits/stdc++.h>
#define GOOD_LUCK ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define itn int
#define INF 100000000
#define MOD 998244353
#define MAX 103
#define endl "\n"
#define ff first
#define ss second
using namespace std;

int temp;
string a;
int n;

string solve(int x, stack <char> s, string& st) {
	if (x == n-1) {
		if (s.empty()) {
			return st;
		}
		else {
			return "-1";
		}
	}
	x++;
	if (s.empty()) {
		s.push(a[x]);
		st = st + '(';
		return solve(x, s, st);
	}
	else if (s.top() == a[x]) {
		string ans1, ans2;
		// 1.
		s.pop();
		st = st + ')';
		ans1 = solve(x, s, st);
		// 2.
		s.push(a[x]);
		s.push(a[x]);
		st = st + '(';
		ans2 = solve(x, s, st);
		return min(ans1, ans2);
	}
	else {
		s.push(a[x]);
		st = st + '(';
		return solve(x, s, st);
	}
}

signed main() {

	GOOD_LUCK

    int t;
	t = 1;
//	cin >> t;
    while (t--) {
        cin >> a;
        n = a.size();
        if (n % 2 != 0) {
        	cout << -1;
        	continue;
		}
		string st;
		stack <char> s;
		cout << solve(-1, s, st);
	}

    return 0;
}
// Problem B
// by Ekber_Ekber
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -