Submission #749592

# Submission time Handle Problem Language Result Execution time Memory
749592 2023-05-28T09:39:03 Z 박상훈(#9965) Match (CEOI16_match) C++17
37 / 100
2000 ms 2036 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int n;
char a[100100], ans[100100];

bool ok(int s, vector<int> st){
	for (int i=s;i<=n;i++){
		if (!st.empty() && st.back()==a[i]) st.pop_back();
		else st.push_back(a[i]);
	}

	return st.empty();
}

int main(){
	scanf("%s", a+1);
	n = strlen(a+1);

	vector<int> st;
	for (int i=1;i<=n;i++){
		st.push_back(a[i]);
		if (ok(i+1, st)) ans[i] = '(';
		else{
			st.pop_back();
			if (!st.empty() && st.back() == a[i]){
				st.pop_back();
				ans[i] = ')';
			}
			else{
				printf("-1\n");
				return 0;
			}
		}
	}
	ans[n+1] = 0;

	printf("%s\n", ans+1);
}

Compilation message

match.cpp: In function 'int main()':
match.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  scanf("%s", a+1);
      |  ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 312 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 5 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 312 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 5 ms 340 KB Output is correct
8 Correct 52 ms 340 KB Output is correct
9 Correct 62 ms 344 KB Output is correct
10 Correct 56 ms 404 KB Output is correct
11 Correct 46 ms 396 KB Output is correct
12 Execution timed out 2061 ms 2036 KB Time limit exceeded
13 Halted 0 ms 0 KB -