# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
874904 | Sir_Ahmed_Imran | Match (CEOI16_match) | C++17 | 2096 ms | 509264 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
///~~~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;
}
Compilation message (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... |