QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#276994 | #7894. Many Many Heads | wenjing233# | WA | 2ms | 3628kb | C++14 | 2.7kb | 2023-12-06 14:16:34 | 2023-12-06 14:16:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int T;
char s[N];
pair<bool,int> dfs(int nw)
{
int opt=0;
if(s[nw]=='(' || s[nw]==')')opt=1;
else opt=2;
int lst=0;
bool tf1=false,tf2=false;
for(int i=nw+1;;)
{
if(s[i]=='(' || s[i]==')')
{
if(lst==0)
{
if(opt==1)
return {false,i};
lst=1;
i++;
}
else if(lst==1)
{
if(tf1)
return {true,0};
else tf1=true;
lst=0;
i++;
}
else
{
auto tmp=dfs(i);
if(tmp.first)return {true,0};
i=tmp.second+1;
}
}
else
{
if(lst==0)
{
if(opt==2)
return {false,i};
lst=2;
i++;
}
else if(lst==2)
{
if(tf2)
return {true,0};
else tf2=true;
lst=0;
i++;
}
else
{
auto tmp=dfs(i);
if(tmp.first)return {true,0};
i=tmp.second+1;
}
}
}
}
bool solve(int l,int r)
{
int lst=0;
bool tf1=false,tf2=false;
for(int i=l;i<=r;)
{
if(s[i]=='(' || s[i]==')')
{
if(lst==0)
{
lst=1;
i++;
}
else if(lst==1)
{
if(tf1)
return true;
else tf1=true;
lst=0;
i++;
}
else
{
auto tmp=dfs(i);
if(tmp.first)return true;
i=tmp.second+1;
}
}
else
{
if(lst==0)
{
lst=2;
i++;
}
else if(lst==2)
{
if(tf2)
return true;
else tf2=true;
lst=0;
i++;
}
else
{
auto tmp=dfs(i);
if(tmp.first)return true;
i=tmp.second+1;
}
}
}
return false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin >> T;
while(T--)
{
cin >> s+1;
if(solve(1,strlen(s+1)))cout << "No\n";
else cout << "Yes\n";
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3448kb
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: 3500kb
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: 2ms
memory: 3628kb
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 Yes Yes Yes No No No Yes No No No No Yes No No No Yes Yes Yes No Yes No No No No No No Yes No No No No No No No No No No Yes Yes No No No No No No...
result:
wrong answer expected NO, found YES [45th token]