Submission #134108

# Submission time Handle Problem Language Result Execution time Memory
134108 2019-07-22T05:33:44 Z 이온조(#3229) Match (CEOI16_match) C++14
37 / 100
2000 ms 756 KB
#include <bits/stdc++.h>
using namespace std;

int N;
char S[100009], ans[100009];

bool chk(vector<char> T, int id) {
	for(int i=id; i<N; i++) {
		if(T.size() && T.back() == S[i]) T.pop_back();
		else T.push_back(S[i]);
	}
	if(T.size()) return 0;
	return 1;
}

int main() {
	scanf("%s", S);
	N = strlen(S);
	vector<char> T;
	for(int i=0; i<N; i++) {
		T.push_back(S[i]);
		if(!chk(T, i+1)) {
			T.pop_back();
			if(T.empty() || S[i] != T.back()) return !printf("-1");
			T.pop_back();
			ans[i] = ')';
		}
		else ans[i] = '(';
	}
	for(int i=0; i<N; i++) printf("%c", ans[i]);
	return 0;
}

Compilation message

match.cpp: In function 'int main()':
match.cpp:17:7: 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 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 420 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 7 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 420 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 7 ms 376 KB Output is correct
8 Correct 86 ms 376 KB Output is correct
9 Correct 109 ms 376 KB Output is correct
10 Correct 71 ms 504 KB Output is correct
11 Correct 59 ms 376 KB Output is correct
12 Execution timed out 2062 ms 756 KB Time limit exceeded
13 Halted 0 ms 0 KB -