# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
53502 | baactree | Match (CEOI16_match) | C++17 | 2 ms | 248 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;
int n;
char str[100005];
int sum[100005];
bool possi[100005];
void solve(int le, int ri) {
if (le > ri)return;
stack<int> st;
for (int i = le; i <= ri; i++) {
if (!st.empty() && st.top() == str[i])st.pop();
else st.push(str[i]);
possi[i] = st.empty();
}
for (int i = ri; i > le; i--) {
if (str[i] == str[le] && possi[i]) {
str[le] = '(';
str[i] = ')';
return;
}
}
return;
}
int main() {
scanf("%s", str + 1);
n = strlen(str + 1);
stack<int> st;
for (int i = 1; i <= n; i++) {
if (!st.empty() && st.top() == str[i])st.pop();
else st.push(str[i]);
}
if (!st.empty())return !printf("-1\n");
solve(1, n);
printf("%s\n", str + 1);
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... |