# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
745451 | Alexandruabcde | Match (CEOI16_match) | C++14 | 2057 ms | 15872 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
constexpr int NMAX = 1e5 + 5;
constexpr int SIGMAX = 26;
bool exist;
int sp[NMAX];
char ans[NMAX];
string S;
void Precompute () {
deque <char> D;
for (int i = 0; i < S.size(); ++ i ) {
if (D.empty() || D.back() != S[i]) {
D.push_back(S[i]);
}
else {
D.pop_back();
}
}
exist = D.empty();
}
int pos[SIGMAX];
int bef[NMAX];
void Solve (int st, int dr) {
if (st > dr) return;
deque <char> D;
int last = -1;
for (int j = st+1; j <= dr; ++ j ) {
if (ans[j] == ')') {
if (D.empty() || D.back() != S[j])
break;
D.pop_back();
continue;
}
if (D.empty() || D.back() != S[j]) {
if (D.empty() && S[st] == S[j])
last = j;
D.push_back(S[j]);
}
else {
D.pop_back();
}
}
ans[st] = '(';
ans[last] = ')';
Solve(st+1, last-1);
Solve(last+1, dr);
}
void Solve () {
Solve(0, S.size()-1);
for (int i = 0; i < S.size(); ++ i )
cout << ans[i];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> S;
Precompute();
if (!exist) {
cout << -1 << '\n';
return 0;
}
Solve();
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... |