QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#298656 | #7894. Many Many Heads | ucup-team045# | WA | 1ms | 3488kb | C++20 | 1.4kb | 2024-01-06 13:51:07 | 2024-01-06 13:51:08 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<array>
using namespace std;
using LL = long long;
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int T;
cin >> T;
while(T--){
string s;
cin >> s;
const int n = s.size();
for(auto &c : s){
if (c == ')') c = '(';
if (c == ']') c = '[';
}
s = " " + s;
vector<array<int, 2> > pre(n + 1);
for(int i = 1; i <= n; i++){
pre[i] = pre[i - 1];
pre[i][(s[i] != '(')] = i;
}
vector<int> dep(n + 1);
auto solve = [&](auto &&solve, int l, int r) -> void {
if (l > r) return;
int k = pre[r][s[l] != '('];
if (s[l] == s[l - 1]){
dep[l] = dep[k] = dep[l - 1] + 1;
}
else{
dep[l] = dep[k] = 1;
}
solve(solve, l + 1, k - 1); solve(solve, k + 1, r);
};
solve(solve, 1, n);
bool ok = true;
for(int i = 1; i + 1 <= n; i++){
if (dep[i] >= 2){
ok = false;
break;
}
}
cout << (ok ? "Yes" : "No") << '\n';
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3436kb
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: -100
Wrong Answer
time: 1ms
memory: 3488kb
input:
2 (([([[([ ]]))])]])]
output:
No No
result:
wrong answer expected YES, found NO [1st token]