# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1118052 | vjudge1 | Match (CEOI16_match) | C++17 | 2045 ms | 592 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.
#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,n;
string a;
cin>>a;
n=a.size();
stack<char>s;
for(i=0;i<n;i++)
{
if(s.size() and s.top()==a[i])
s.pop();
else
s.push(a[i]);
}
if(s.size())
{
cout<<-1<<endl;
return 0;
}
string z="";
for(i=0;i<n;i++)
{
stack<char>st;
for(j=0;j<i;j++)
{
if(z[j]=='(')
st.push(a[j]);
else
st.pop();
}
st.push(a[i]);
for(j=i+1;j<n;j++)
{
if(st.size() and st.top()==a[j])
st.pop();
else
st.push(a[j]);
}
if(st.size())
z+=')';
else
z+='(';
}
cout<<z<<endl;
}
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... |