# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
809092 | nonono | Match (CEOI16_match) | C++14 | 8 ms | 340 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 mxN = 1e5 + 10;
int n;
string s;
namespace sub {
int mark[mxN];
bool check() {
vector<int> q;
for(int i = 1; i <= n; i ++) {
if(mark[i]) {
q.push_back(i - 1);
continue ;
}
if(!q.empty() && s[q.back()] == s[i - 1]) q.pop_back();
else {
q.push_back(i - 1);
}
}
return q.size() == 0;
}
int main() {
for(int i = 1; i <= n; i ++) mark[i] = 0;
if(!check()) {
return cout << -1, 0;
}
for(int i = 1; i <= n; i ++) {
mark[i] = 1;
mark[i] = check();
}
for(int i = 1; i <= n; i ++) cout << (mark[i] ? '(' : ')');
return 0;
}
}
int main() {
#define taskname ""
if(fopen(taskname".inp", "r")) {
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
cin >> s;
n = s.size();
if(n <= 2000) sub :: main();
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... |