Submission #53502

#TimeUsernameProblemLanguageResultExecution timeMemory
53502baactree괄호 문자열 (CEOI16_match)C++17
0 / 100
2 ms248 KiB
#include <bits/stdc++.h> using namespace std; int n; char str[100005]; int sum[100005]; bool possi[100005]; void solve(int le, int ri) { if (le > ri)return; stack<int> st; for (int i = le; i <= ri; i++) { if (!st.empty() && st.top() == str[i])st.pop(); else st.push(str[i]); possi[i] = st.empty(); } for (int i = ri; i > le; i--) { if (str[i] == str[le] && possi[i]) { str[le] = '('; str[i] = ')'; return; } } return; } int main() { scanf("%s", str + 1); n = strlen(str + 1); stack<int> st; for (int i = 1; i <= n; i++) { if (!st.empty() && st.top() == str[i])st.pop(); else st.push(str[i]); } if (!st.empty())return !printf("-1\n"); solve(1, n); printf("%s\n", str + 1); return 0; }

Compilation message (stderr)

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