# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
699032 | cpLover22 | 괄호 문자열 (CEOI16_match) | C++17 | 2080 ms | 616 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |