| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 608507 | SeDunion | 괄호 문자열 (CEOI16_match) | C++17 | 706 ms | 10960 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<assert.h>
#include<vector>
#include<string>
using namespace std;
int n;
string s, ans;
#define cerr if(false)cerr
const int N = 1e5 + 123;
int L[N][26];
void get(int l, int r) {
if (l > r) return;
if (s[l] == s[r]) {
ans[l] = '(';
ans[r] = ')';
get(l+1,r-1);
return;
}
int i = L[r][s[l]-'a'];
if (i == -1) {
cout << -1;
exit(0);
}
if (i != -1) {
ans[l] = '(';
ans[i] = ')';
get(l+1,i-1);
get(i+1,r);
return;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin >> s;
n = s.size();
for (int i = 0 ; i < n ; ++ i) cerr << i;
cerr << endl;
for (int i = 0 ; i < n ; ++ i) {
for (int c = 0 ; c < 26 ; ++ c) {
L[i][c] = -1;
}
}
for (int i = 0 ; i < n ; ++ i) {
if (i>=2 && s[i - 1] == s[i]) {
L[i][s[i-2]-'a'] = i-2;
}
if (i) L[i][s[i]-'a'] = max(L[i][s[i]-'a'], L[i-1][s[i]-'a']);
L[i][s[i]-'a']=i;
if (i) {
int j = L[i-1][s[i]-'a'];
if (j > 0) {
--j;
for (int a = 0 ; a < 26 ; ++ a) {
L[i][a] = max(L[i][a], L[j][a]);
}
}
}
for (int rep = 0 ; rep < 10 ; ++ rep) {
for (int a = 0 ; a < 26 ; ++ a) {
for (int b = 0 ; b < 26 ; ++ b) {
int j = L[i][b];
if (j == -1) continue;
L[i][a] = max(L[i][a], L[j][a]);
}
}
}
}
for (int i = 0 ; i < n ; ++ i) {
cerr << i << " ";
for (int j = 0 ; j < 26 ; ++ j) {
if (L[i][j] == -1) cerr << "- ";
else cerr << L[i][j] << " ";
}
cerr << endl;
}
ans = string(n, '-');
get(0, n - 1);
for (int i = 0 ; i < n ; ++ i) cerr << i;
cerr << endl;
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
