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