# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
244728 | evpipis | Match (CEOI16_match) | C++11 | 2067 ms | 880 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int len = 1e5+5;
char str[len], out[len];
stack<char> main_stack;
int n;
bool check(int i){
stack<char> sec_stack(main_stack);
sec_stack.push(str[i++]);
while (i < n){
if (sec_stack.empty() || sec_stack.top() != str[i])
sec_stack.push(str[i]);
else
sec_stack.pop();
i++;
}
return sec_stack.empty();
}
int main(){
scanf("%s", str);
n = strlen(str);
int ans = 1;
for (int i = 0; i < n; i++){
int test = check(i);
if (!test && main_stack.empty()){
ans = 0;
break;
}
//printf("i = %d, test = %d\n", i, test);
if (test)
main_stack.push(str[i]), out[i] = '(';
else
main_stack.pop(), out[i] = ')';
}
if (!ans){
printf("-1\n");
return 0;
}
for (int i = 0; i < n; i++)
printf("%c", out[i]);
printf("\n");
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |