QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#591594 | #5534. Match | xiay | 10 | 1888ms | 7932kb | C++14 | 1.3kb | 2024-09-26 16:41:30 | 2024-09-26 16:41:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
string s;
int a[N];
int sum[30][N];
int n;
stack <char> st;
int lst[N], nxt[N];
bool check(int l, int r) {
for (int i = 0; i < 26; i++) {
if ((sum[i][r] - sum[i][l - 1]) & 1) {
return 0;
}
}
int sum = 0;
for (int i = l; i <= r; i++) {
if (!a[i]) {
sum++;
}
else {
if (!sum) {
return 0;
}
sum--;
}
}
return 1;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("test.in", "r", stdin);
freopen("test.out", "w", stdout);
#endif
cin >> s;
n = s.size();
s = " " + s;
for (int i = 1; i <= n; i++) {
nxt[lst[s[i] - 'a']] = i;
lst[s[i] - 'a'] = i;
if (st.empty() || st.top() != s[i]) {
st.push(s[i]);
}
else {
st.pop();
a[i] = 1;
}
for (int j = 0; j < 26; j++) {
sum[j][i] = sum[j][i - 1];
}
sum[s[i] - 'a'][i]++;
}
if (!st.empty()) {
puts("-1");
return 0;
}
while (1. * clock() / CLOCKS_PER_SEC < 1.97) {
for (int j = 1; j <= n; j++) {
if (nxt[j] && a[nxt[j]] < a[j]) {
if (check(j + 1, nxt[j] - 1)) {
swap(a[nxt[j]], a[j]);
}
}
}
}
for (int i = 1; i <= n; i++) {
if (a[i]) {
putchar(')');
}
else {
putchar('(');
}
}
return 0;
}
詳細信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 734ms
memory: 5840kb
input:
abbaaa
output:
(()())
result:
ok single line: '(()())'
Test #2:
score: 10
Accepted
time: 924ms
memory: 3768kb
input:
cbbbbccbbccbbbbbbc
output:
(((((((()))())))))
result:
ok single line: '(((((((()))())))))'
Test #3:
score: 10
Accepted
time: 1ms
memory: 3900kb
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: 1888ms
memory: 7932kb
input:
fsooskkkksokkkkossskkiffoofooikkiiiiiooikkkksookkiissiooookskffsskiiksskiikfiifkifofssooffffkfiiiifkfsiisfsofossiffissikskiikkkiikokikkffkiiksffkkiossifkiookioffoikkkoiiiooioiffkkkssfoooiiiioioskksisikkkoifiooikkkkfiffississkskiofffiffiiiosksskfffofisksksskiisikkskkkksoosiffoofoiooioooifiifssfffffoi...
output:
((((((())))(()))())()(((()((((()(()))))((())(()()((())(())(((()(((())))(()))()))((((()()(())(((())))((()))(((((((())))((((()(()())(((((())())(()()((()((((()(((()))())((()())))()())())(()(()))))(()))))()))(((())(()))(())())())))))())(()())))(())()))))))((())()))()((()))()))()())((())()))(()(()(()))((...
result:
wrong answer 1st lines differ - expected: '((((((())))(()))(((()(((()((((...))(())(()))(())())))))))((())))', found: '((((((())))(()))())()(((()((((...))(())(()))(())()))()(()(()))))'
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%