Submission #53500

# Submission time Handle Problem Language Result Execution time Memory
53500 2018-06-30T06:29:55 Z baactree Match (CEOI16_match) C++17
37 / 100
2000 ms 33564 KB
#include <bits/stdc++.h>
using namespace std;
int n;
char str[100005];
int sum[100005];
bool possi[100005];
bool solve(int le, int ri) {
	if (le > ri)return true;
	stack<int> st;
	for (int i = le; i <= ri; i++) {
		if (!st.empty() && st.top() == str[i])st.pop();
		else st.push(str[i]);
		possi[i] = st.empty();
	}
	for (int i = ri; i > le; i--) {
		if (str[i] == str[le] && possi[i]) {
			str[le] = '(';
			str[i] = ')';
			return solve(le + 1, i - 1) && solve(i + 1, ri);
		}
	}
	return false;
}
int main() {
	scanf("%s", str + 1);
	n = strlen(str + 1);
	if(solve(1, n))	printf("%s\n", str + 1);
	else printf("-1\n");
	return 0;
}

Compilation message

match.cpp: In function 'int main()':
match.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", str + 1);
  ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 636 KB Output is correct
5 Correct 3 ms 636 KB Output is correct
6 Correct 5 ms 1056 KB Output is correct
7 Correct 4 ms 1056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 636 KB Output is correct
5 Correct 3 ms 636 KB Output is correct
6 Correct 5 ms 1056 KB Output is correct
7 Correct 4 ms 1056 KB Output is correct
8 Correct 8 ms 1056 KB Output is correct
9 Correct 46 ms 2180 KB Output is correct
10 Correct 28 ms 2180 KB Output is correct
11 Correct 37 ms 3384 KB Output is correct
12 Correct 1673 ms 26900 KB Output is correct
13 Correct 1934 ms 33564 KB Output is correct
14 Execution timed out 2057 ms 33564 KB Time limit exceeded
15 Halted 0 ms 0 KB -