QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#217563 | #5534. Match | Camillus | 10 | 1ms | 3468kb | C++20 | 1.5kb | 2023-10-16 23:48:31 | 2023-10-16 23:48:31 |
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 {
auto rec = [&](auto &&rec, int l, int r) -> void {
if (l > r) {
return;
}
if (s[l] == s[r]) {
t[l] = '(';
t[r] = ')';
rec(rec, l + 1, r - 1);
} else {
vector<int> q;
int best = l;
for (int i = r; i >= l; i--) {
if (!q.empty() && s[q.back()] == s[i]) {
q.pop_back();
} else {
q.push_back(i);
}
if (q.empty()) {
best = i;
break;
}
}
rec(rec, l, best - 1);
rec(rec, best, r);
}
};
rec(rec, 0, n - 1);
cout << t << '\n';
}
return 0;
}
详细
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 1ms
memory: 3412kb
input:
abbaaa
output:
(()())
result:
ok single line: '(()())'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3468kb
input:
cbbbbccbbccbbbbbbc
output:
(((((((()))())))))
result:
ok single line: '(((((((()))())))))'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3432kb
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: 0ms
memory: 3460kb
input:
fsooskkkksokkkkossskkiffoofooikkiiiiiooikkkksookkiissiooookskffsskiiksskiikfiifkifofssooffffkfiiiifkfsiisfsofossiffissikskiikkkiikokikkffkiiksffkkiossifkiookioffoikkkoiiiooioiffkkkssfoooiiiioioskksisikkkoifiooikkkkfiffississkskiofffiffiiiosksskfffofisksksskiisikkskkkksoosiffoofoiooioooifiifssfffffoi...
output:
((((((())))()())()(()(((()((((()()())))((((((()()()()((())((((((((())))(()))()))((((((()()()(((())))((())))((((((())))(((((((()())(((((())())(()()((()(((((((((()))()))()(())))()())())()((()))))(()))))()))(((())()()))())())())))))())(())()))(())()))))))((())()))())))))(()))))())((()))())(()))(((())((...
result:
wrong answer 1st lines differ - expected: '((((((())))(()))(((()(((()((((...))(())(()))(())())))))))((())))', found: '((((((())))()())()(()(((()((((...))()()(()))(())()))()))(((())))'
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%