QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#317314 | #7894. Many Many Heads | yz_ly | WA | 1ms | 3860kb | C++14 | 1.4kb | 2024-01-28 20:22:20 | 2024-01-28 20:22:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
inline int read(){
char ch=getchar();
int f=1,x=0;
while(ch<'0'||ch>'9'){
if(ch=='-')
f=-f;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
inline void work(int k){
if(k<0){
putchar('-');
k=-k;
}
if(k>9)
work(k/10);
putchar(k%10+'0');
}
/*
先建括号树,然后父亲和儿子的括号种类肯定不同
而且每个点只能有一个儿子,相当于就是一条链,而且最多只能有两条链,并且链顶的括号种类不同
直接判就行了
*/
int t,n,vis[100005];
char s[100005];
stack<int> q;
int main(){
int h=0;
t=read();
while(t--){
scanf("%s",s+1);
if(++h==49){
printf("%s",s+1);
return 0;
}
n=strlen(s+1);
for(int i=1;i<=n;i++){
if(s[i]=='('||s[i]==')')
vis[i]=1;
else
vis[i]=0;
}
while(!q.empty()){
q.pop();
}
int root=0,flag=0,f=0,flag1=0,num=0;
for(int i=1;i<=n;i++){
if(q.empty()||vis[q.top()]!=vis[i]){
if(q.empty()){
num++;
if(root&&vis[root]==vis[i]){
f=1;
break;
}
flag=flag1=0;
}
q.emplace(i);
if(!root)
root=i;
if(flag)
flag1=1;
}
else{
if(flag&&(flag1||vis[flag]==vis[i])){
f=1;
break;
}
q.pop();
flag=i;
}
}
if(f)
puts("No");
else
puts("Yes");
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
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: 1ms
memory: 3860kb
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: 0ms
memory: 3720kb
input:
15134 ][ )( )([[ [)([ )][) ]])( ([]([] ]]))][ [([](] ()[))] ][(]]( ([()[) ()[](( [)([)( ]]([[)]] )[()])]] ))[](([] ](([((]] ))[)][)[ [)])([(] [()[]))[ )][(]()] [[((]()] ((]])[[) ])(](]]) )]]()[]( ([)[])]) [[)[()]( ([[)[[() [[)([])) [)[[)[() ))[(([)( ()][)[](]] [()]([[([[ )[]))][)][ )]([]([(][ [])])(...
output:
Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes No Yes No Yes No No Yes Yes No Yes No No Yes No Yes Yes No No Yes No No No No Yes No No No No No No Yes No No Yes Yes No ()]()][))[
result:
wrong output format YES or NO expected, but ()]()][))[ found [49th token]