# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1118034 |
2024-11-24T18:37:01 Z |
vjudge1 |
Match (CEOI16_match) |
C++17 |
|
5 ms |
336 KB |
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define AI ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
vector<ll>val;
vector<vector<ll>>edge;
vector<ll>check;
ll k,c=0;
int main()
{
AI
//freopen(“kangaroo.in”, “r”, stdin);
// freopen(“kangaroo.out”, “w”, stdout);
ll i,j,k;
string a;
cin>>a;
if(a.size()%2)
{
cout<<-1;
return 0;
}//1->( 0->)
ll n=a.size();
string str=" ";
for(i=(1<<(n/2))-1;i<(1<<n);i++)
{
ll bal=0;
k=1;
for(j=0;j<n;j++)
{
if(i&k)
bal++;
else
bal--;
if(bal<0)
break;
k=(k<<1);
}
if(bal!=0)
continue;
stack<ll>stm;
stack<ll>sta;
char x;
bool bo=true;
k=1;
for(j=0;j<n;j++)
{
// cout<<k;
if(i&k)
x='(';
else
x=')';
k=(k<<1);
if(!stm.size())
{
stm.push(x);
sta.push(a[j]);
continue;
}
if(stm.top()=='(' and x==')' and sta.top()!=a[j])
{
bo=false;
break;
}
else if(stm.top()=='(' and x==')' and sta.top()==a[j])
{
sta.pop();
stm.pop();
}
else
{
sta.push(a[j]);
stm.push(x);
}
}
if(stm.size() or sta.size() or !bo)
continue;
else
{
k=1;
string xx="";
for(j=0;j<n;j++)
{
if(i&k)
xx+="(";
else
xx+=")";
k=(k<<1);
}
if(str==" ")
str=xx;
else
str=min(str,xx);
}
}
if(str==" ")
cout<<-1;
else
cout<<str;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
5 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
5 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
5 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |