QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#346580 | #7894. Many Many Heads | Freeuni1# | WA | 18ms | 3884kb | C++14 | 1.6kb | 2024-03-08 18:07:52 | 2024-03-08 18:07:52 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
main() {
ios::sync_with_stdio(0);
int t;
cin >> t;
while (t --) {
string x;
cin >> x;
int n = x.size();
vector<int> w(n + 5),v(n + 5), pr(n + 5), nx(n + 5), fx(n + 5);
queue<int> q;
int ii = 1;
v[ii] = 1;
w[0] = (x[0] == '(' || x[0] == ')');
for (int i = 1; i < x.size(); i ++) {
w[i] = (x[i] == '(' || x[i] == ')');
if (w[i] == w[i-1]) v[ii] ++;
else {
if (v[ii] >= 2) {q.push(ii);}
pr[ii] = ii - 1;
nx[ii] = ii + 1;
ii ++;
v[ii] = 1;
}
}
pr[ii] = ii-1;
nx[ii] = ii + 1;
//cout << v[ii] << "!!";
if (v[ii] >= 2)q.push(ii);
int sm = 0, ok = 1;
while (q.size()) {
int k = q.front();
//cout << k << " " << v[k] << endl;
q.pop();
if (fx[k]) continue;
if (v[k] != 2) {
ok = 0;
break;
}
sm += 2;
if (pr[k] == 0 || nx[k] > ii) {
continue;
}
v[pr[k]] += v[nx[k]];
nx[pr[k]] = nx[nx[k]];
pr[nx[nx[k]]] = pr[pr[k]];
fx[nx[k]] = 1;
//cout <<"^^"<< k << " " << pr[k] << endl;
q.push(pr[k]);
}
if (!ok || sm != n) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
input:
6 )) ((() [()] ()[()]() ([()]) ([])([])
output:
Yes No Yes No Yes No
result:
ok 6 token(s): yes count is 3, no count is 3
Test #2:
score: 0
Accepted
time: 0ms
memory: 3884kb
input:
2 (([([[([ ]]))])]])]
output:
Yes No
result:
ok 2 token(s): yes count is 1, no count is 1
Test #3:
score: -100
Wrong Answer
time: 18ms
memory: 3588kb
input:
15134 ][ )( )([[ [)([ )][) ]])( ([]([] ]]))][ [([](] ()[))] ][(]]( ([()[) ()[](( [)([)( ]]([[)]] )[()])]] ))[](([] ](([((]] ))[)][)[ [)])([(] [()[]))[ )][(]()] [[((]()] ((]])[[) ])(](]]) )]]()[]( ([)[])]) [[)[()]( ([[)[[() [[)([])) [)[[)[() ))[(([)( ()][)[](]] [()]([[([[ )[]))][)][ )]([]([(][ [])])(...
output:
Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes No Yes No Yes No Yes Yes Yes No Yes No No Yes No Yes Yes Yes No Yes No No Yes No Yes No No No No No No Yes No No Yes Yes No No No Yes No Yes Yes No Yes No No No Yes Yes No No Yes No No No No No No Yes No Yes No No No Yes No No No No Yes No No Yes No No ...
result:
wrong answer expected NO, found YES [18th token]