| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 202300 | quocnguyen1012 | 괄호 문자열 (CEOI16_match) | C++14 | 21 ms | 12148 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
int N;
int last[maxn][26];
string str;
char res[maxn];
void match(int l, int r)
{
if (l > r) return;
if (l % 2 == r % 2){
cout << -1;
exit(0);
}
int mid = last[r][str[l] - 'a'];
res[l] = '('; res[mid] = ')';
match(l + 1, mid - 1);
match(mid + 1, r);
}
signed main(void)
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen("A.INP", "r")){
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
}
cin >> str; N = str.size();
str = " " + str;
for (int i = 0; i < 26; ++i){
last[0][i] = 1;
}
for (int i = 1; i <= N; ++i){
for (int j = 0; j < 26; ++j){
if (str[i] - 'a' == j){
last[i][j] = i;
}
else{
last[i][j] = last[last[i - 1][str[i] - 'a'] - 1][j];
}
}
}
match(1, N);
for (int i = 1; i <= N; ++i){
cout << res[i];
}
}
컴파일 시 표준 에러 (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... | ||||
