# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
761772 | Tenis0206 | Match (CEOI16_match) | C++11 | 30 ms | 62640 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;
const int nmax = 1e5;
string s;
string rez;
int l[nmax + 5][155];
bool ok = true;
void solve(int st, int dr)
{
if(st > dr)
{
return;
}
int poz = l[dr][s[st]];
if(poz==-1 || poz <= st)
{
ok = false;
return;
}
rez[st] = '(';
rez[poz] = ')';
solve(st+1,poz-1);
solve(poz+1,dr);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef home
freopen("nr.in","r",stdin);
freopen("nr.out","w",stdout);
#endif // home
cin>>s;
int n = s.size();
rez.resize(n + 1);
s = "#" + s;
for(int c='a';c<='z'; c++)
{
l[0][c] = -1;
}
for(int i=1;i<=n;i++)
{
for(int c='a';c<='z';c++)
{
l[i][c] = -1;
}
int poz = l[i - 1][s[i]];
if(s[i - 1] == s[i])
{
poz = i - 1;
}
l[i][s[i]] = i;
if(poz == -1)
{
continue;
}
l[i][s[poz - 1]] = max(l[i][s[poz-1]], poz - 1);
for(int c='a';c<='z';c++)
{
l[i][c] = max(l[i][c], l[poz - 1][c]);
}
}
solve(1,n);
if(!ok)
{
cout<<-1<<'\n';
return 0;
}
for(int i=1; i<=n; i++)
{
cout<<rez[i];
}
cout<<'\n';
return 0;
}
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... |