# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1118032 |
2024-11-24T18:30:44 Z |
vjudge1 |
Match (CEOI16_match) |
C++17 |
|
1 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();
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;
for(j=0;j<n;j++)
{
if(i&k)
cout<<'(';
else
cout<<')';
k=(k<<1);
}
return 0;
}
}
cout<<-1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |