#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
using namespace std;
ifstream cin("match.in");
ofstream cout("match.out");
constexpr int nmax = 1e5 + 2;
int n,v[nmax],frecv[nmax],deschis[nmax],nr;
char s[nmax];
int main()
{
cin.getline((s + 1),nmax);
int n = strlen(s + 1);
for(int i = 1; i <= n; i++)
{
int ch = s[i] - '0' + 1;
v[i] = ch;
if(frecv[ch] == 0)
{
deschis[++nr] = ch;
frecv[ch]++;
}
else
{
if(deschis[nr] == ch)
{
frecv[ch]--;
nr--;
}
else
{
cout << "-1";
return 0;
}
}
}
if(nr > 0)
{
cout << "-1";
return 0;
}
for(int i = 1; i <= n; i++)
{
int ch = v[i];
if(frecv[ch] == 0)
{
int ci = i, cnt = 0;
while(v[ci] == ch && ci <= n)
{
cnt++;
ci++;
}
ci--;
int j = 1;
for(; j <= (cnt + 1) / 2; j++)
{
cout << "(";
}
for(; j <= cnt; j++)
{
cout << ")";
}
i = ci;
frecv[ch] = cnt % 2;
}
else
{
int ci = i, cnt = 0;
while(v[ci] == ch && ci <= n)
{
cnt++;
ci++;
}
ci--;
int j = 1;
for(; j <= cnt / 2; j++)
{
cout << "(";
}
for(; j <= cnt; j++)
{
cout << ")";
}
i = ci;
frecv[ch] = (1 + cnt) % 2;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |