# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1032662 | 2024-07-24T05:49:32 Z | 정민찬(#10967) | Match (CEOI16_match) | C++17 | 1 ms | 604 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pll; string s; bool Check(vector<char> st, int idx) { for (int i=idx; i<s.size(); i++) { if (!st.empty() && st.back() == s[i]) st.pop_back(); else st.push_back(s[i]); } return st.empty(); } string Cal(int l, int r) { if (l > r) return ""; int idx; for (int i=r; i>=l; i--) { if (s[i] == s[l]) { idx = i; break; } } assert(idx > l); return "(" + Cal(l+1, idx-1) + ")" + Cal(idx+1, r); } int main() { ios_base :: sync_with_stdio(false); cin.tie(NULL); cin >> s; if (!Check({}, 0)) { cout << "-1\n"; return 0; } cout << Cal(0, s.size()-1) << '\n'; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 452 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 452 KB | Output is correct |
4 | Runtime error | 1 ms | 604 KB | Execution killed with signal 6 |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 452 KB | Output is correct |
4 | Runtime error | 1 ms | 604 KB | Execution killed with signal 6 |
5 | Halted | 0 ms | 0 KB | - |