| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 339681 | couplefire | 괄호 문자열 (CEOI16_match) | C++17 | 2 ms | 364 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100005
int n; string s;
int dp[MAXN];
string ans;
bool solve(int l, int r){
if(l == r+1) return 1;
if(dp[l] == -1) return false;
ans[l] = '('; ans[dp[l]] = ')';
return solve(l+1, dp[l]-1) && solve(dp[l]+1, r);
}
int main(){
freopen("match.in", "r", stdin);
freopen("match.out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> s; n = s.length();
ans.resize(n);
dp[n] = -1;
for(int i = n-1; i>=0; i--){
dp[i] = -1;
if(i != n-1 && s[i] == s[i+1]) dp[i] = i+1;
int cur = i+1;
while(dp[cur] != -1){
cur = dp[cur]+1;
if(cur != n && s[cur] == s[i]) dp[i] = cur;
}
}
if(!solve(0, n-1)) cout << -1 << endl;
else cout << ans << endl;
}
컴파일 시 표준 에러 (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... | ||||
