# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
53504 | 2018-06-30T06:32:42 Z | baactree | 괄호 문자열 (CEOI16_match) | C++17 | 2000 ms | 26372 KB |
#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] = ')'; solve(le + 1, i - 1); solve(i + 1, ri); 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 356 KB | Output is correct |
3 | Correct | 3 ms | 432 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 356 KB | Output is correct |
3 | Correct | 3 ms | 432 KB | Output is correct |
4 | Correct | 1 ms | 692 KB | Output is correct |
5 | Correct | 2 ms | 692 KB | Output is correct |
6 | Correct | 7 ms | 1096 KB | Output is correct |
7 | Correct | 4 ms | 1096 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 356 KB | Output is correct |
3 | Correct | 3 ms | 432 KB | Output is correct |
4 | Correct | 1 ms | 692 KB | Output is correct |
5 | Correct | 2 ms | 692 KB | Output is correct |
6 | Correct | 7 ms | 1096 KB | Output is correct |
7 | Correct | 4 ms | 1096 KB | Output is correct |
8 | Correct | 9 ms | 1096 KB | Output is correct |
9 | Correct | 60 ms | 2152 KB | Output is correct |
10 | Correct | 42 ms | 2152 KB | Output is correct |
11 | Correct | 92 ms | 3188 KB | Output is correct |
12 | Execution timed out | 2048 ms | 26372 KB | Time limit exceeded |
13 | Halted | 0 ms | 0 KB | - |