Submission #608301

# Submission time Handle Problem Language Result Execution time Memory
608301 2022-07-27T06:50:42 Z SeDunion Match (CEOI16_match) C++17
37 / 100
429 ms 34304 KB
#include<iostream>
#include<assert.h>
#include<vector>
#include<string>

using namespace std;

int n;
string s, ans;

const int N = 2022;

int dp[N][N];
int us[N][N];

int solve(int l, int r) {
	if (l > r) return 1;
	if (us[l][r]) return dp[l][r];
	us[l][r] = 1;
	for (int i = r ; i > l ; i -= 2) {
		if (s[i] == s[l] && solve(l+1, i-1) && solve(i + 1, r)) {
			return dp[l][r] = 1;
		}
	}
	return dp[l][r];
}

void get(int l, int r) {
	if (l > r) return;
	for (int i = r ; i > l ; i -= 2) {
		if (s[i] == s[l] && solve(i + 1, r)) {
			assert(solve(l+1,i-1));
		//if (s[i] == s[l] && solve(l+1, i-1) && solve(i + 1, r)) {
			ans[l] = '(';
			ans[i] = ')';
			get(l + 1, i - 1);
			get(i + 1, r);
			return;
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin >> s;
	n = s.size();
	if (!solve(0, n-1)) {
		cout << -1;
		return 0;
	}
	ans = string(n, '-');
	get(0, n - 1);
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 51 ms 8008 KB Output is correct
5 Correct 11 ms 7636 KB Output is correct
6 Correct 4 ms 6484 KB Output is correct
7 Correct 429 ms 19968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 51 ms 8008 KB Output is correct
5 Correct 11 ms 7636 KB Output is correct
6 Correct 4 ms 6484 KB Output is correct
7 Correct 429 ms 19968 KB Output is correct
8 Runtime error 263 ms 34304 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -