QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#217067 | #5534. Match | Camillus# | 0 | 0ms | 3844kb | C++20 | 1.0kb | 2023-10-16 13:51:28 | 2024-07-04 02:20:12 |
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 {
vector<int> cnt(26);
for (int i = 0; i < n; i++) {
cnt[s[i] - 'a'] += 1;
}
vector<int> cur(26);
for (int i = 0; i < n; i++) {
cur[s[i] - 'a'] += 1;
if (cur[s[i] - 'a'] <= cnt[s[i] - 'a'] / 2) {
cout << '(';
} else {
cout << ')';
}
}
cout << '\n';
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 0ms
memory: 3620kb
input:
abbaaa
output:
(()())
result:
ok single line: '(()())'
Test #2:
score: -10
Wrong Answer
time: 0ms
memory: 3844kb
input:
cbbbbccbbccbbbbbbc
output:
((((((((()))))))))
result:
wrong answer 1st lines differ - expected: '(((((((()))())))))', found: '((((((((()))))))))'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%