| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 341627 | phathnv | 괄호 문자열 (CEOI16_match) | C++11 | 1 ms | 364 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 1;
const int AL = 26;
int n, match[N], pre[N][AL], answer[N];
string s;
void readInput(){
cin >> s;
n = s.size();
s = '*' + s;
}
void process(int l, int r){
if (l > r)
return;
int best = pre[r][s[l] - 'a'];
if (match[l] == best){
answer[l] = 1;
answer[best] = 2;
process(l + 1, best - 1);
} else {
int a = match[l];
int b = match[best];
answer[l] = 1;
answer[match[l]] = 1;
answer[match[best]] = 2;
answer[best] = 2;
process(l + 1, match[l] - 1);
process(match[l] + 1, match[best] - 1);
process(match[best] + 1, best - 1);
}
process(best + 1, r);
}
void solve(){
stack <int> st;
for(int i = 1; i <= n; i++){
if (st.empty()){
st.push(i);
} else if (s[st.top()] == s[i]){
match[st.top()] = i;
match[i] = st.top();
st.pop();
for(int j = 0; j < AL; j++)
pre[i][j] = pre[match[i] - 1][j];
pre[i][s[i] - 'a'] = i;
} else {
st.push(i);
}
}
if (!st.empty()){
cout << -1;
return;
}
process(1, n);
for(int i = 1; i <= n; i++)
cout << (answer[i] == 1? '(' : ')');
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
readInput();
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
