QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#799576 | #7894. Many Many Heads | Tom22l | WA | 7ms | 7736kb | C++17 | 1.5kb | 2024-12-05 15:57:53 | 2024-12-05 15:57:54 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int read()
{
int x = 0, f = 1;
char c = getchar();
while(c != EOF and !isdigit(c))
{
if(c == '-')f = -1;
c = getchar();
}
while(isdigit(c))
{
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
struct node{
int id;char c;
};
int n;
stack<node>st;
string s;
int fa[1000005];
int cnt1[1000005];
int cnt2[1000005];
signed main()
{
int T = read();
while(T --)
{
cin>>s;
while(! st.empty())st.pop();
for(int i = 0;i < s.size();i ++) cnt1[i]=0,cnt2[i]=0;
int nf=0,nid=0;
bool flag=0;
for(int i = 0;i < s.size();i ++)
{
if(st.empty())
{
char w;
if(s[i] == '(' or s[i] == ')'){
fa[++nid]=nf;
if(cnt1[nf]){
flag=1;break;
}cnt1[nf]++;
st.push({nid,'('});
}
else{
fa[++nid]=nf;
if(cnt2[nf]){
flag=1;break;
}cnt2[nf]++;
st.push({nid,'['});
}nf=nid;
continue;
}
node x = st.top();
if(s[i] == '(' or s[i] == ')'){
if(x.c == '('){
nf=fa[x.id];
st.pop();
}else{
fa[++nid]=nf;
if(cnt1[nf]){
flag=1;break;
}cnt1[nf]++;
st.push({nid,'('});
}
}
else if(s[i] == '[' or s[i] == ']'){
if(x.c == '['){
nf=fa[x.id];
st.pop();
}else{
fa[++nid]=nf;
if(cnt2[nf]){
flag=1;break;
}cnt2[nf]++;
st.push({nid,'['});
}
}
}
if(!flag) cout<<"Yes\n";
else cout<<"No\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7720kb
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: 7736kb
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: 7724kb
input:
15134 ][ )( )([[ [)([ )][) ]])( ([]([] ]]))][ [([](] ()[))] ][(]]( ([()[) ()[](( [)([)( ]]([[)]] )[()])]] ))[](([] ](([((]] ))[)][)[ [)])([(] [()[]))[ )][(]()] [[((]()] ((]])[[) ])(](]]) )]]()[]( ([)[])]) [[)[()]( ([[)[[() [[)([])) [)[[)[() ))[(([)( ()][)[](]] [()]([[([[ )[]))][)][ )]([]([(][ [])])(...
output:
Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes No Yes No Yes No No Yes No No Yes No No Yes No No Yes No No Yes No No No No No No No No No No No Yes No No No No No No No Yes No No No No Yes No No No No No 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 [20th token]