| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1117714 | vjudge1 | Match (CEOI16_match) | C++17 | 71 ms | 336 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.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int sz=2e5+5;
const int MOD=1e9+7;
const int INF=1e18;
bool check(string cur,string s,int b,int e)
{
map<int,bool> used;
for(int i=b;i<e;i++)
{
bool checker=false;
if(used[i])
continue;
used[i]=true;
for(int j=e-1;j>=b;j--)
{
if(s[j]==s[i] && cur[i]=='(' && cur[j]==')' && !used[j])
{
used[j]=true;
checker=check(cur,s,i+1,j);
break;
}
}
if(!checker)
return false;
}
return true;
}
void solve()
{
string s,res="",checker="";
cin>>s;
for(int i=0;i< s.size();i++)
{
res+=')';
checker+=')';
}
int n=s.size();
for(int mask=1;mask<(1<<n);mask++)
{
string cur="";
for(int j=0;j<n;j++)
{
if(mask & (1<<j))
cur+='(';
else
cur+=')';
}
if(check(cur,s,0,s.size()))
res=min(res,cur);
}
if(res==checker)
cout<<-1;
else
cout<<res;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
//cin>>t;
while(t--)
{
solve();
}
}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... | ||||
