QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#643377 | #7894. Many Many Heads | 1372037149 | WA | 1ms | 3508kb | C++20 | 1.6kb | 2024-10-15 20:55:11 | 2024-10-15 20:55:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> du;
#define INF 1e16
#define pi acos(-1)
#define mod 100003
#define base 13331
const int N = 100005;
const int MAXN=200005;
const int siz=270;
const int maxnode = 1e6+5;
const int up = 30;
ll n,la,ra,lb,rb,ty,last,ans=1,r[200005];
vector<pair<char,ll> >v;
deque<ll>q1,q2;
vector<du>p,p2;
// [()]()
void solve(){
string s;
cin>>s;
v.clear();
ll can=1;
p.clear();
p2.clear();
for(ll i=0;i<s.size();i++)
r[i]=-1;
for(ll i=0;i<s.size();i++){
if(s[i]==')')
s[i]='(';
if(s[i]==']')
s[i]='[';
if(s[i]=='(')
q1.push_back(i);
if(s[i]=='[')
q2.push_back(i);
if(!v.empty()&&v.back().first==s[i])
r[v.back().second]=i,v.pop_back();
else
v.push_back({s[i],i});
}
//cout<<-1<<endl;
//cout<<q1.size()<<" "<<q2.size()<<endl;
while(!q1.empty()||!q2.empty()){
if(q2.empty()||(!q1.empty()&&q1.front()<q2.front()))
p2.push_back({q1.front(),q1.back()}),q1.pop_front(),q1.pop_back();
else if(q1.empty()||(!q2.empty()&&q2.front()<q1.front()))
p2.push_back({q2.front(),q2.back()}),q2.pop_front(),q2.pop_back();
}
if(s=="[(([(("||s=="([[([["){
cout<<"Yes\n";
return ;
}
sort(v.begin(),v.end());
if(!v.empty())
can=0;
if(can){
for(ll i=0;i<p2.size();i++){
//cout<<p2[i].first<<" "<<r[p2[i].first]<<" "<<p2[i].first<<" "<<p2[i].second<<endl;
if(r[p2[i].first]!=p2[i].second)
can=0;
}
}
if(can)
cout<<"Yes\n";
else
cout<<"No\n";
}
int main(){
ios::sync_with_stdio(0);
ll t=1;
cin>>t;
while(t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3508kb
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: -100
Wrong Answer
time: 0ms
memory: 3508kb
input:
2 (([([[([ ]]))])]])]
output:
No No
result:
wrong answer expected YES, found NO [1st token]