# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
96931 | Kastanda | 괄호 문자열 (CEOI16_match) | C++11 | 19 ms | 11888 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// I do it for the glory
#include<bits/stdc++.h>
using namespace std;
const int N = 100005, SGM = 26;
int n, C[N][SGM];
char A[N], B[N];
void Solve(int l, int r)
{
if (r <= l)
return ;
int opt = C[r - 1][A[l] - 'a'];
if (opt <= l)
{printf("-1\n"); exit(0);}
B[l] = '('; B[opt] = ')';
Solve(l + 1, opt);
Solve(opt + 1, r);
}
int main()
{
scanf("%s", A);
n = strlen(A);
memset(C, -1, sizeof(C));
for (int i = 0; i < n; i++)
for (int j = 0; j < SGM; j++)
{
if (A[i] - 'a' == j)
C[i][j] = i;
else if (i > 0 && C[i - 1][A[i] - 'a'] > 0)
C[i][j] = C[C[i - 1][A[i] - 'a'] - 1][j];
}
Solve(0, n);
return !printf("%s\n", B);
}
컴파일 시 표준 에러 (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... |