# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
53515 | 2018-06-30T06:50:23 Z | baactree | 괄호 문자열 (CEOI16_match) | C++17 | 5 ms | 3620 KB |
#include <bits/stdc++.h> using namespace std; int n; char str[100005]; vector<int> p[256][256]; int s[100005]; void solve(int le, int ri) { if (le > ri)return; auto it = upper_bound(p[s[le - 1]][str[le]].begin(), p[s[le - 1]][str[le]].end(), ri); int i = *(--it); str[le] = '('; str[i] = ')'; solve(le + 1, i - 1); solve(i + 1, ri); 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"); st.push(0); p[0][0].push_back(0); s[0] = 0; for (int i = 1; i <= n; i++) { if (st.top() == str[i])st.pop(); else st.push(str[i]); p[st.top()][str[i]].push_back(i); s[i] = st.top(); } solve(1, n); printf("%s\n", str + 1); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1912 KB | Output is correct |
2 | Correct | 3 ms | 2004 KB | Output is correct |
3 | Correct | 3 ms | 2004 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1912 KB | Output is correct |
2 | Correct | 3 ms | 2004 KB | Output is correct |
3 | Correct | 3 ms | 2004 KB | Output is correct |
4 | Runtime error | 5 ms | 3620 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1912 KB | Output is correct |
2 | Correct | 3 ms | 2004 KB | Output is correct |
3 | Correct | 3 ms | 2004 KB | Output is correct |
4 | Runtime error | 5 ms | 3620 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
5 | Halted | 0 ms | 0 KB | - |