Submission #244728

#TimeUsernameProblemLanguageResultExecution timeMemory
244728evpipisMatch (CEOI16_match)C++11
37 / 100
2067 ms880 KiB
#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)

match.cpp: In function 'int main()':
match.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", str);
     ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...