QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#729947 | #7894. Many Many Heads | retired_midlights | WA | 12ms | 4008kb | C++14 | 1.4kb | 2024-11-09 18:05:26 | 2024-11-09 18:05:27 |
Judging History
answer
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
int st[100010];
int fd(char ch)
{
if(ch == '#')return 2;
return (ch=='['||ch==']')?1:0;
}
int main()
{
int i,j,k,n,m,x,y,z,t;
scanf("%d",&t);
while(t--)
{
string s;
cin>>s;
s='#'+s+'#';
n=s.size();
x=0;
int la=-1;
int fl=0;
for(i=0;i<n;i++)
{
if(la!=fd(s[i]))
{
if(x>0)
{
if(st[x-1]>2)
{
fl=1;
break;
}
else if(st[x-1]==2)
{
x--;
if(x==0)
{
break;
}
st[x-1]++;
}
else
{
st[x]=1;
x++;
}
la=fd(s[i]);
}
else
{
la=fd(s[i]);
st[x]=1;
x++;
}
}
else
{
st[x-1]++;
}
}
if(fl)
{
printf("No\n");
continue;
}
la=0;
x=0;
for(i=1;i<n;i++)
{
if(fd(s[i])!=fd(s[i-1]))
{
if(x==2)
{
la++;
}if(x>2){
la=100;
}
x=1;
}
else
{
x++;
}
}
if(la>2)
{
printf("No\n");
}
else
{
printf("Yes\n");
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3724kb
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: 3804kb
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: 12ms
memory: 4008kb
input:
15134 ][ )( )([[ [)([ )][) ]])( ([]([] ]]))][ [([](] ()[))] ][(]]( ([()[) ()[](( [)([)( ]]([[)]] )[()])]] ))[](([] ](([((]] ))[)][)[ [)])([(] [()[]))[ )][(]()] [[((]()] ((]])[[) ])(](]]) )]]()[]( ([)[])]) [[)[()]( ([[)[[() [[)([])) [)[[)[() ))[(([)( ()][)[](]] [()]([[([[ )[]))][)][ )]([]([(][ [])])(...
output:
Yes Yes No Yes Yes No No No Yes Yes Yes Yes No No No No No No Yes Yes No Yes No No Yes No Yes Yes No No No No No No No No No No No No No No Yes No No Yes Yes No No No Yes No No No No Yes No No No Yes Yes No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No No No...
result:
wrong answer expected YES, found NO [3rd token]