QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#661692 | #7894. Many Many Heads | Yuu | WA | 1ms | 3660kb | C++23 | 3.1kb | 2024-10-20 17:37:06 | 2024-10-20 17:37:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
// The 2023 ICPC Asia Jinan Regional Contest
void sol(){
std::string s;
std::cin>>s;
int n = s.length();
std::vector<int>vis(n);
for(int i = 0;i<n;i++){
if(s[i] == '(' || s[i] == ')') vis[i] = 1;
}
std::vector<int>p1,p2;
for(int i = 0;i<n;i++){
if(s[i] =='(' || s[i] == ')') p1.push_back(i);
if(s[i] == '[' || s[i] == ']') p2.push_back(i);
}
if(n == 2){
std::cout<<"YES\n";
return ;
}
if(p1.size() == 0){
std::cout<<(p2.size() > 2?"NO\n":"YES\n");
return ;
}
if(p2.size() == 0){
std::cout<<(p1.size() > 2?"NO\n":"YES\n");
return ;
}
int ok = 0;
for(int i = 1;i<p1.size();i++){
int d = p1[i] - p1[i - 1] - 1;
if(d > 2){
ok = 1;
break;
}
}
for(int i = 1;i<p2.size();i++){
int d = p2[i] - p2[i - 1] - 1;
if(d > 2){
ok = 1;
break;
}
}
if(p1[0] < p2[0] && p2[0] > 2){
ok = 1;
}
if(p2[0] < p1[0] && p1[0] > 2){
ok = 1;
}
if(ok){
std::cout<<"NO\n";
return ;
}
if(p2.size() == 2){
if(p2[0] >= 2 && n - p2[1] >= 2){
std::cout<<"NO\n";
return ;
}
if(vis[0] == vis[1] && vis[1] == vis[2]){
std::cout<<"NO\n";
return ;
}
if(vis[n - 1] == vis[n - 2] && vis[n - 2] == vis[n - 3]){
std::cout<<"NO\n";
return ;
}
std::cout<<"YES\n";
return ;
}
if(p1.size() == 2){
if(p1[0] >= 2 && n - p1[1] >= 2){
std::cout<<"NO\n";
return ;
}
if(vis[0] == vis[1] && vis[1] == vis[2]){
std::cout<<"NO\n";
return ;
}
if(vis[n - 1] == vis[n - 2] && vis[n - 2] == vis[n - 3]){
std::cout<<"NO\n";
return ;
}
std::cout<<"YES\n";
return ;
}
// 每一种类型至少有两个完整括号
// 任意两个相邻的相同括号之间最多只有两个其他括号
int tot = 0;
for(int i = p2[0] + 1;i < n - 1;i++){
if(vis[i] == 1 && vis[i + 1] == 1) tot++;
}
if(tot >= 2){
std::cout<<"NO\n";
return ;
}
if(tot == 1){
if(vis[n - 1] == vis[n - 2] || vis[0] == vis[1]) {
std::cout<<"NO\n";
return ;
}
}
tot = 0;
for(int i = p1[0] + 1;i<n - 1;i++){
if(vis[i] == 0 && vis[i + 1] == 0) tot++;
}
if(tot >= 2){
std::cout<<"NO\n";
return ;
}
if(tot == 1){
if(vis[n - 1] == vis[n - 2] || vis[0] == vis[1]) {
std::cout<<"NO\n";
return ;
}
}
std::cout<<"YES\n";
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t = 1; std::cin>>t;
while(t--) sol();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3636kb
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: 3660kb
input:
2 (([([[([ ]]))])]])]
output:
NO NO
result:
wrong answer expected YES, found NO [1st token]