# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
30818 | zscoder | 괄호 문자열 (CEOI16_match) | C++14 | 2000 ms | 31392 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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<int,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;
bool err;
string s;
void solve(int l, int r)
{
if(l>r) return ;
stack<char> S;
string ans;
int idx=-1;
if(s[l]==s[r])
{
solve(l+1,r-1);
if(err) return ;
s[l]='('; s[r]=')';
return ;
}
for(int i = r; i > l; i--)
{
if(!S.empty()&&S.top()==s[i])
{
S.pop();
}
else
{
S.push(s[i]);
}
if(s[l]==s[i-1]&&S.empty())
{
idx=i;
break;
}
}
if(idx<=l)
{
err=true;
return ;
}
solve(l+1,idx-2);
solve(idx,r);
s[l]='('; s[idx-1]=')';
}
char a[100011];
int main()
{
scanf("%s", a);
int idx=0;
while(a[idx]!='\0')
{
s+=a[idx];
idx++;
}
solve(0,int(s.length())-1);
if(err) cout<<-1<<'\n';
else cout<<s<<'\n';
}
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... |