# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1032683 | 2024-07-24T06:09:08 Z | 정민찬(#10967) | 괄호 문자열 (CEOI16_match) | C++17 | 1620 ms | 86992 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(); } void Cal(int l, int r) { if (l > r) return; vector<char> st; int idx; for (int i=r; i>=l; i--) { if (s[i] == s[l] && st.empty()) { idx = i; break; } if (!st.empty() && st.back() == s[i]) st.pop_back(); else st.push_back(s[i]); } cout << "("; Cal(l+1, idx-1); cout << ")"; 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; } Cal(0, s.size()-1); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 456 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 456 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 2 ms | 344 KB | Output is correct |
9 | Correct | 8 ms | 860 KB | Output is correct |
10 | Correct | 3 ms | 860 KB | Output is correct |
11 | Correct | 2 ms | 860 KB | Output is correct |
12 | Correct | 64 ms | 9904 KB | Output is correct |
13 | Correct | 30 ms | 6492 KB | Output is correct |
14 | Correct | 432 ms | 50848 KB | Output is correct |
15 | Correct | 5 ms | 4696 KB | Output is correct |
16 | Correct | 7 ms | 4576 KB | Output is correct |
17 | Correct | 65 ms | 6708 KB | Output is correct |
18 | Correct | 8 ms | 2396 KB | Output is correct |
19 | Correct | 752 ms | 48972 KB | Output is correct |
20 | Correct | 285 ms | 38000 KB | Output is correct |
21 | Correct | 1620 ms | 86992 KB | Output is correct |