# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
874904 | Sir_Ahmed_Imran | Match (CEOI16_match) | C++17 | 2096 ms | 509264 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define li long int
#define ld long double
#define append push_back
#define add insert
#define nl "\n"
#define ff first
#define ss second
#define pii pair<int,int>
#define pic pair<int,char>
#define all(x) (x).begin(),(x).end()
#define sum(a) accumulate(all(a),0)
#define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL)
#define terminator main
#define N 20001
int dp[N][N];
void solve(){
string a;
int n,m,o,p,q,r;
cin>>a;
n=a.size();
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
dp[i][j]=0;
for(int j=1;j<n;j++){
for(int i=0;i<n-j;i++){
dp[i][i+j]=(a[i]==a[i+j] &&
(dp[i+1][i+j-1] || j==1));
for(int k=i+2;k<i+j;k++)
dp[i][i+j]|=(dp[i][k-1] && dp[k][i+j]);
}
}
if(!dp[0][n-1]){
cout<<-1;
return;
}
set<int> s{n};
for(int i=0;i<n;i++){
o=0;
for(int j=i+1;j<*s.lower_bound(i);j++){
if((dp[i+1][j-1] || j-i==1)
&& a[i]==a[j] && a[i]!=')') o=j;
}
if(o){
s.add(o);
a[i]='(';
a[o]=')';
}
else a[i]=')';
cout<<a[i];
}
}
int terminator(){
L0TA;
solve();
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... |