# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
42432 | nonocut | Match (CEOI16_match) | C++14 | 19 ms | 820 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;
#define pci pair<char,int>
#define X first
#define Y second
const int maxn = 2e3 + 5;
int n;
char s[maxn];
int fix[maxn];
pci a[maxn];
bool check() {
int r = 0;
for(int i=0;i<n;i++) {
a[++r] = {s[i],fix[i]};
while(r>=2 && a[r].X==a[r-1].X) {
if(a[r].Y==0 || (a[r-1].Y==-1 && a[r].Y==1)) r-=2;
else break;
}
}
return (r==0);
}
int main() {
scanf(" %s",s);
n = strlen(s);
for(int i=0;i<n;i++) {
fix[i] = -1;
if(!check()) fix[i] = 1;
}
if(check()) {
for(int i=0;i<n;i++) printf("%c", (fix[i]==-1 ? '(' : ')'));
}
else printf("-1");
}
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... |