Submission #42432

# Submission time Handle Problem Language Result Execution time Memory
42432 2018-02-27T06:43:06 Z nonocut Match (CEOI16_match) C++14
37 / 100
19 ms 820 KB
#include<bits/stdc++.h>
using namespace std;
#define pci pair<char,int>
#define X first
#define Y second
const int maxn = 2e3 + 5;
int n;
char s[maxn];
int fix[maxn];
pci a[maxn];
bool check() {
	int r = 0;
	for(int i=0;i<n;i++) {
		a[++r] = {s[i],fix[i]};
		while(r>=2 && a[r].X==a[r-1].X) {
			if(a[r].Y==0 || (a[r-1].Y==-1 && a[r].Y==1)) r-=2;
			else break;
		}
	}
	return (r==0);
}
int main() {
	scanf(" %s",s);
	n = strlen(s);
	for(int i=0;i<n;i++) {
		fix[i] = -1;
		if(!check()) fix[i] = 1;
	}
	if(check()) {
		for(int i=0;i<n;i++) printf("%c", (fix[i]==-1 ? '(' : ')'));
	}
	else printf("-1");
}

Compilation message

match.cpp: In function 'int main()':
match.cpp:23:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf(" %s",s);
                ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 2 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 2 ms 464 KB Output is correct
4 Correct 5 ms 572 KB Output is correct
5 Correct 5 ms 576 KB Output is correct
6 Correct 17 ms 684 KB Output is correct
7 Correct 19 ms 688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 2 ms 464 KB Output is correct
4 Correct 5 ms 572 KB Output is correct
5 Correct 5 ms 576 KB Output is correct
6 Correct 17 ms 684 KB Output is correct
7 Correct 19 ms 688 KB Output is correct
8 Runtime error 2 ms 820 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Halted 0 ms 0 KB -