QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#752169 | #7894. Many Many Heads | veg# | WA | 0ms | 3884kb | C++14 | 788b | 2024-11-15 22:27:23 | 2024-11-15 22:27:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
char s[maxn];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s",s+1);
int cnt1=0,cnt2=0,n=strlen(s+1);
for(int i=1;i<=n;i++)
if(s[i]=='('||s[i]==')') cnt1++;
else cnt2++;
if(cnt1&1||cnt2&1) puts("No");
else
{
cnt1/=2,cnt2/=2;
for(int i=1;i<=n;i++)
if(s[i]=='('||s[i]==')')
{
if(cnt1>0) s[i]='(';
else s[i]=')';
cnt1--;
}
else
{
if(cnt2>0) s[i]='[';
else s[i]=']';
cnt2--;
}
printf("%s",s+1);
for(int i=1;i<n;i++)
if(s[i]==s[i+1]) goto L;
if(s[1]=='('&&s[n]==')'||s[1]=='['&&s[n]==']')
{
puts("Yes");
continue;
}
L:puts("No");
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3884kb
input:
6 )) ((() [()] ()[()]() ([()]) ([])([])
output:
()Yes (())No [()]Yes (([()]))No ([()])Yes ([[()]])No
result:
wrong output format YES or NO expected, but ()YES found [1st token]