QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#279331 | #7894. Many Many Heads | superguymj | WA | 5ms | 6036kb | C++14 | 966b | 2023-12-08 16:11:42 | 2023-12-08 16:11:42 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define mid ((l+r)>>1)
using namespace std;
const int N=1000005;
char s[N];
int n,a[N];
bool check(int l,int r)
{
if(l>r) return 0;
rep(i,l,mid-1) if(a[i]==a[i+1]) return 0;
rep(i,mid+1,r-1) if(a[i]==a[i+1]) return 0;
return 1;
}
void solve()
{
scanf("%s",s+1),n=strlen(s+1);
vector <int> stk;
rep(i,1,n)
{
int c=(s[i]=='(' || s[i]==')');
a[i]=c;
if(!stk.empty() && a[stk.back()]==c)
{
if(c) s[i]=')';
else s[i]=']';
stk.pop_back();
}
else
{
if(c) s[i]='(';
else s[i]='[';
stk.push_back(i);
}
}
rep(i,1,n-1) if(s[i]==')' && s[i+1]=='(')
return puts("No"),void();
rep(i,1,n-1) if(s[i]==']' && s[i+1]=='[')
return puts("No"),void();
if(check(1,n) || check(3,n) || check(1,n-2))
return puts("Yes"),void();
puts("No");
}
int main()
{
int t;
scanf("%d",&t);
while(t--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5752kb
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: 5812kb
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: 5ms
memory: 6036kb
input:
15134 ][ )( )([[ [)([ )][) ]])( ([]([] ]]))][ [([](] ()[))] ][(]]( ([()[) ()[](( [)([)( ]]([[)]] )[()])]] ))[](([] ](([((]] ))[)][)[ [)])([(] [()[]))[ )][(]()] [[((]()] ((]])[[) ])(](]]) )]]()[]( ([)[])]) [[)[()]( ([[)[[() [[)([])) [)[[)[() ))[(([)( ()][)[](]] [()]([[([[ )[]))][)][ )]([]([(][ [])])(...
output:
Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes No Yes No Yes No No Yes Yes No No No No No No Yes Yes No No Yes No No No No Yes No No No No No No No No No Yes Yes No No No No No No No No No No No No Yes Yes No No No No No No No No No Yes No No No No No No No No No No Yes No No No No No No No No No No...
result:
wrong answer expected YES, found NO [22nd token]