Submission #53484

# Submission time Handle Problem Language Result Execution time Memory
53484 2018-06-30T05:56:40 Z baactree Match (CEOI16_match) C++17
10 / 100
2 ms 652 KB
#include <bits/stdc++.h>
using namespace std;
int n;
char str[100005];
int sum[100005];
void solve(int le, int ri) {
	if (le > ri)return;
	for (int i = ri; i > le; i--) {
		if (str[i] == str[le] && (sum[i] ^ sum[le - 1]) == 0) {
			str[i] = ')';
			str[le] = '(';
			solve(le + 1, i - 1);
			solve(i + 1, ri);
			return;
		}
	}
	printf("-1\n");
	exit(0);
}
int main() {
	scanf("%s", str + 1);
	n = strlen(str + 1);
	for (int i = 1; i <= n; i++)
		sum[i] = sum[i - 1] ^ (1 << (str[i] - 'a'));
	solve(1, n);
	printf("%s\n", str + 1);
	return 0;
}

Compilation message

match.cpp: In function 'int main()':
match.cpp:21: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 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Incorrect 2 ms 652 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Incorrect 2 ms 652 KB Output isn't correct
5 Halted 0 ms 0 KB -