# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
53125 | youngyojun | 괄호 문자열 (CEOI16_match) | C++11 | 22 ms | 12604 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define upmax(a,b) (a)=max((a),(b))
using namespace std;
void fuk() { puts("-1"); exit(0); }
const int MAXN = 100005;
int dp[MAXN][26];
char Ans[MAXN];
int B[MAXN];
char A[MAXN];
int N;
void f(int s, int e) {
if(s > e) return;
if((e-s+1)&1) fuk();
if(s+1 == e) {
if(B[s] != B[e]) fuk();
Ans[s] = '(';
Ans[e] = ')';
return;
}
int k = dp[e][B[s]];
if(k < s) fuk();
Ans[s] = '(';
Ans[k] = ')';
f(s+1, k-1);
f(k+1, e);
}
int main() {
scanf(" %s", A+1);
N = int(strlen(A+1));
if(N&1) fuk();
for(int i = 1; i <= N; i++)
B[i] = A[i]-'a';
for(int i = 1, j; i <= N; i++) {
dp[i][B[i]] = i;
j = dp[i-1][B[i]];
if(j < 2) continue;
upmax(dp[i][B[j-1]], j-1);
for(int c = 0; c < 26; c++)
upmax(dp[i][c], dp[j-1][c]);
}
f(1, N);
for(int i = 1; i <= N; i++)
putchar(Ans[i]);
puts("");
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... |