# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
129981 | TadijaSebez | 괄호 문자열 (CEOI16_match) | C++11 | 20 ms | 11640 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N=100050;
char s[N],ans[N];
int pre[N][26];
bool ok=1;
void Solve(int l, int r)
{
if(l>r) return;
int m=pre[r][s[l]-'a'];
if(m<=l){ ok=0;return;}
ans[l]='(';
ans[m]=')';
Solve(l+1,m-1);
Solve(m+1,r);
}
int main()
{
int n;
scanf("%s",s+1);
n=strlen(s+1);
for(int i=1;i<=n;i++) for(int j=0;j<26;j++)
{
if(j==s[i]-'a') pre[i][j]=i;
else if(pre[i-1][s[i]-'a']>0) pre[i][j]=pre[pre[i-1][s[i]-'a']-1][j];
else pre[i][j]=0;
}
Solve(1,n);
if(ok) printf("%s",ans+1);
else printf("-1\n");
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... |