Submission #134335

# Submission time Handle Problem Language Result Execution time Memory
134335 2019-07-22T13:02:29 Z imyujin Match (CEOI16_match) C++14
37 / 100
9 ms 504 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 2005;

int N;
char s[MAXN];
char ans[MAXN];

bool ava(stack<char> st, int x) {
	for(int i = x; i < N; i++) {
		if(!st.empty() && s[i] == st.top()) st.pop();
		else st.push(s[i]);
	}
	return st.empty();
}

int main() {
	cin >> s;
	for(N = 0; s[N]; N++);

	stack<char> st;
	for(int i = 0; i < N; i++) {
		st.push(s[i]);
		if(ava(st, i + 1)) ans[i] = '(';
		else {
			ans[i] = ')';
			st.pop();
			if(st.empty() || st.top() != s[i]) {
				cout << -1;
				return 0;
			}
			st.pop();
		}
	}
	if(st.empty()) for(int i = 0; i < N; i++) cout << ans[i];
	else cout << -1;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 6 ms 252 KB Output is correct
7 Correct 9 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 6 ms 252 KB Output is correct
7 Correct 9 ms 376 KB Output is correct
8 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Halted 0 ms 0 KB -