QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#217066 | #5534. Match | Camillus# | 10 | 368ms | 3616kb | C++20 | 1.4kb | 2023-10-16 13:40:10 | 2024-07-04 02:20:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
signed main() {
#ifndef LOCAL
ios::sync_with_stdio(false);
cin.tie(nullptr);
#else
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
string s;
cin >> s;
int n = (int)s.size();
string t = s;
vector<int> q;
for (int i = 0; i < n; i++) {
if (!q.empty() && s[q.back()] == s[i]) {
t[i] = ')';
q.pop_back();
} else {
t[i] = '(';
q.push_back(i);
}
}
if (!q.empty()) {
cout << -1 << '\n';
} else {
while (true) {
vector<int> b(n);
for (int x = 0, i = 0; i < n; i++) {
if (t[i] == '(') {
x += 1;
} else {
x -= 1;
}
b[i] = x;
}
bool ok = false;
for (int i = 0; i < n && !ok; i++) {
for (int j = i + 1; j < n && !ok; j++) {
if (s[i] == s[j] && t[i] == ')' && t[j] == '(' && b[j] == b[i] + 1) {
ok = true;
swap(t[i], t[j]);
}
}
}
if (!ok) {
break;
}
}
cout << t << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 3592kb
input:
abbaaa
output:
(()())
result:
ok single line: '(()())'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
cbbbbccbbccbbbbbbc
output:
(((((((()))())))))
result:
ok single line: '(((((((()))())))))'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
ddbcbdacccbddaba
output:
-1
result:
ok single line: '-1'
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #4:
score: 0
Wrong Answer
time: 368ms
memory: 3556kb
input:
fsooskkkksokkkkossskkiffoofooikkiiiiiooikkkksookkiissiooookskffsskiiksskiikfiifkifofssooffffkfiiiifkfsiisfsofossiffissikskiikkkiikokikkffkiiksffkkiossifkiookioffoikkkoiiiooioiffkkkssfoooiiiioioskksisikkkoifiooikkkkfiffississkskiofffiffiiiosksskfffofisksksskiisikkskkkksoosiffoofoiooioooifiifssfffffoi...
output:
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((()))()()))(()())()))(((()())())()()()))())))(()()))))()(((()())()))())))))((())()())()())())(())())()))))(...
result:
wrong answer 1st lines differ - expected: '((((((())))(()))(((()(((()((((...))(())(()))(())())))))))((())))', found: '((((((((((((((((((((((((((((((...))(())())))()))()()))())(()))))'
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%