Submission #53502

# Submission time Handle Problem Language Result Execution time Memory
53502 2018-06-30T06:31:53 Z baactree Match (CEOI16_match) C++17
0 / 100
2 ms 248 KB
#include <bits/stdc++.h>
using namespace std;
int n;
char str[100005];
int sum[100005];
bool possi[100005];
void solve(int le, int ri) {
	if (le > ri)return;
	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;
		}
	}
	return;
}
int main() {
	scanf("%s", str + 1);
	n = strlen(str + 1);
	stack<int> st;
	for (int i = 1; i <= n; i++) {
		if (!st.empty() && st.top() == str[i])st.pop();
		else st.push(str[i]);
	}
	if (!st.empty())return !printf("-1\n");
	solve(1, n);
	printf("%s\n", str + 1);
	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 Incorrect 2 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -