QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#664486 | #7894. Many Many Heads | dyfhpu | WA | 20ms | 3628kb | C++17 | 1.7kb | 2024-10-21 20:52:39 | 2024-10-21 20:52:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
const int N = 110;
int a[N];
int st[N];
void solve()
{
string s;cin>>s;
s=" "+s;
int cnt1=0,cnt2=0;
map<int,int> mp1,mp2;
mp1[0]=0;mp2[0]=0;
int cnt=1;
for(int i=1;i<s.size();i++) {
if(s[i]==')') s[i]='(';
if(s[i]==']') s[i]='[';
if(s[i]=='(') {
if(s[i]!=s[i-1]&&(cnt1%2!=0||cnt2%2!=0)) {
if(mp1[cnt-1]%2==1&&mp2[cnt]%2!=1)
{
cnt--;
mp1[cnt]++;
}
else {
cnt++;
mp1[cnt]++;
}
}
else {
mp1[cnt]++;
}
cnt1++;
// cout<<i<<' '<<cnt<<' '<<mp1[cnt]<<endl;
if(mp1[cnt]>2) {
cout<<"No"<<endl;
return ;
}
}
else {
if(s[i]!=s[i-1]&&(cnt1%2!=0||cnt2%2!=0)){
if(mp2[cnt-1]%2==1&&mp1[cnt]%2!=1){
cnt--;
mp2[cnt]++;
}
else {
cnt++;
mp2[cnt]++;
}
}
else mp2[cnt]++;
if(mp2[cnt]>2) {
cout<<"No"<<endl;
return ;
}
cnt2++;
}
// cout<<i<<' '<<cnt<<endl;
}
if(cnt1%2!=0||cnt2%2!=0) {
cout<<"No"<<endl;
return ;
}
cout<<"Yes"<<endl;
return ;
}
int main()
{
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3564kb
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: 3628kb
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: 20ms
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 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 Yes No No No No No No No No No No Yes No No No No No No No No...
result:
wrong answer expected YES, found NO [1437th token]