# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
59579 | octopuses | Match (CEOI16_match) | C++17 | 3 ms | 380 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.
//Giorgi Kldiashvili
#include <bits/stdc++.h>
#define ll long long
#define fr first
#define sc second
#define M 1000000007ll
using namespace std;
const int N = 100020;
int n;
char ch[N];
string a;
inline bool go(int v, stack < int > q)
{
q.pop();
for(int i = v; i <= n; ++ i)
{
if(!q.size() || a[q.top()] != a[i])
q.push(i);
else
q.pop();
}
if(q.size())
return false;
return true;
}
stack < int > q;
int main()
{
scanf("%s", &ch);
a = "$" + string(ch) + "$";
n = strlen(ch);
for(int i = 1; i <= n; ++ i)
{
if(!q.size() || a[q.top()] != a[i])
q.push(i);
else
q.pop();
}
if(q.size())
return printf("-1"), 0;
while(q.size()) q.pop();
q.push(1); printf("(");
for(int i = 2; i <= n; ++ i)
{
if(!q.size() || a[q.top()] != a[i])
q.push(i), printf("(");
else
{
if(go(i + 1, q))
q.pop(), printf(")");
else
q.push(i), printf("(");
}
}
}
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... |