Submission #52914

# Submission time Handle Problem Language Result Execution time Memory
52914 2018-06-27T07:19:49 Z 김세빈(#1383) Match (CEOI16_match) C++11
37 / 100
13 ms 572 KB
#include <bits/stdc++.h>

using namespace std;

char str[101010], ans[101010];
vector <char> V;
int n;

bool check(int p)
{
	int i;
	
	V.clear();
	
	for(i=0;i<=p;i++){
		if(ans[i] == '(') V.push_back(str[i]);
		else V.pop_back();
	}
	
	for(;i<n;i++){
		if(V.empty() || V.back() != str[i]) V.push_back(str[i]);
		else V.pop_back();
	}
	
	return V.empty();
}

int main()
{
	int i;
	
	scanf("%s",str);
	
	for(n=0;str[n];n++);
	
	if(n > 2000) return 0;
	
	ans[0] = '(';
	if(!check(0)){
		printf("-1\n");
		return 0;
	}
	
	for(i=0;i<n;i++){
		ans[i] = '(';
		if(!check(i)) ans[i] = ')';
	}
	
	ans[n] = '\0';
	
	printf("%s\n",ans);
	
	return 0;
}

Compilation message

match.cpp: In function 'int main()':
match.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",str);
  ~~~~~^~~~~~~~~~
# 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 492 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 492 KB Output is correct
4 Correct 5 ms 492 KB Output is correct
5 Correct 4 ms 492 KB Output is correct
6 Correct 7 ms 528 KB Output is correct
7 Correct 13 ms 528 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 492 KB Output is correct
4 Correct 5 ms 492 KB Output is correct
5 Correct 4 ms 492 KB Output is correct
6 Correct 7 ms 528 KB Output is correct
7 Correct 13 ms 528 KB Output is correct
8 Incorrect 2 ms 572 KB Output isn't correct
9 Halted 0 ms 0 KB -