# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
699032 | 2023-02-15T11:38:23 Z | cpLover22 | 괄호 문자열 (CEOI16_match) | C++17 | 2000 ms | 616 KB |
#include <bits/stdc++.h> using namespace std; #define eb emplace_back #define siz(x) (int)x.size() const int N = 1e5 + 5; int n; string st; char res[N]; bool check(stack<int> s, int k) { stack<int> tmp = s; for (int i = k; i <= n; ++i) if (!siz(s)) s.emplace(i); else { if (st[i] == st[s.top()]) s.pop(); else s.emplace(i); } return siz(s) == 0; } int main() { cin.tie(0)->sync_with_stdio(0); cout.tie(0); if (fopen("match.in", "r")) { freopen("match.in", "r", stdin); freopen("match.out", "w", stdout); freopen("log.txt", "w", stderr); } cin >> st; n = st.size(); st = ' ' + st; stack<int> cur; for (int i = 1; i <= n; ++i) { if (!cur.size()) { cur.emplace(i); res[i] = '('; } else { cur.emplace(i); if (check(cur, i + 1)) res[i] = '('; else { cur.pop(); if (st[cur.top()] != st[i]) return cout << -1, 0; else cur.pop(), res[i] = ')'; } } } if (siz(cur)) return cout << -1, 0; for (int i = 1; i <= n; ++i) cout << res[i]; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 328 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 328 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 4 ms | 212 KB | Output is correct |
5 | Correct | 4 ms | 212 KB | Output is correct |
6 | Correct | 8 ms | 340 KB | Output is correct |
7 | Correct | 16 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 328 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 4 ms | 212 KB | Output is correct |
5 | Correct | 4 ms | 212 KB | Output is correct |
6 | Correct | 8 ms | 340 KB | Output is correct |
7 | Correct | 16 ms | 340 KB | Output is correct |
8 | Correct | 178 ms | 340 KB | Output is correct |
9 | Correct | 202 ms | 340 KB | Output is correct |
10 | Correct | 163 ms | 476 KB | Output is correct |
11 | Correct | 146 ms | 348 KB | Output is correct |
12 | Execution timed out | 2080 ms | 616 KB | Time limit exceeded |
13 | Halted | 0 ms | 0 KB | - |