QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#661725 | #7894. Many Many Heads | Yuu | WA | 7ms | 3880kb | C++23 | 2.7kb | 2024-10-20 17:47:05 | 2024-10-20 17:47: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, tot1 = 0, tot2 = 0;
for(int i = 0;i<n - 1;i++){
if(vis[i] == vis[i+1] && vis[i] == 0) tot1++;
if(vis[i] == vis[i+1] && vis[i] == 1) tot2++;
}
if(tot1 >= 2 || tot1 >= 2){
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: 0ms
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: 0
Accepted
time: 0ms
memory: 3880kb
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: 7ms
memory: 3648kb
input:
15134 ][ )( )([[ [)([ )][) ]])( ([]([] ]]))][ [([](] ()[))] ][(]]( ([()[) ()[](( [)([)( ]]([[)]] )[()])]] ))[](([] ](([((]] ))[)][)[ [)])([(] [()[]))[ )][(]()] [[((]()] ((]])[[) ])(](]]) )]]()[]( ([)[])]) [[)[()]( ([[)[[() [[)([])) [)[[)[() ))[(([)( ()][)[](]] [()]([[([[ )[]))][)][ )]([]([(][ [])])(...
output:
YES YES YES YES YES YES YES NO YES YES YES YES NO YES NO YES NO YES YES YES YES YES YES NO YES NO YES YES NO NO YES NO NO NO NO NO NO NO NO NO YES NO NO NO NO YES YES NO YES NO YES YES YES NO NO NO YES NO YES NO YES YES YES YES YES NO YES NO YES YES YES YES YES YES NO NO NO NO NO NO NO YES NO NO YES...
result:
wrong answer expected NO, found YES [18th token]