QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#717769 | #7894. Many Many Heads | shuanglin | WA | 6ms | 3868kb | C++14 | 1.8kb | 2024-11-06 18:55:10 | 2024-11-06 18:55:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define lowbit(x) ((x) & - (x))
using PII = pair<int, int>;
using PIII = tuple<int, int, int>;
const int MOD = 1e9 + 7;
inline int mypow(int n, int k, int p = MOD) {
int r = 1;
for (; k; k >>= 1, n = n * n % p) {
if (k & 1) r = r * n % p;
}
return r;
}
struct cmp { //priority_queue
bool operator()(const PIII& a, const PIII& b) {
return std::get<0>(a) < std::get<0>(b); //down
}
};
bool cmpsort(const PII& a, const PII& b) { //sort
return a.first < b.first; //up
}
string str;
deque <pair<int,char> > e;
map<int,int> mp1;
map<int,int> mp2;
inline void solve() {
cin>>str;
str=" "+str;
for(int i=1;i<str.size();i++){
if(e.empty()){
e.push_back(make_pair(i,str[i]));
continue;
}
if(str[i]=='('||str[i]==')'){
if(e.back().second=='['){
e.push_back(make_pair(i,'('));
}
else{
e.pop_back();
mp1[e.size()]++;
}
}
else{
if(e.back().second=='('){
e.push_back(make_pair(i,'['));
}
else{
e.pop_back();
mp2[e.size()]++;
}
}
}
for(auto it:mp1){
if(it.second>=2){
cout<<"No"<<'\n';
return ;
}
}
for(auto it:mp2){
if(it.second>=2){
cout<<"No"<<'\n';
return ;
}
}
cout<<"Yes"<<'\n';
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0); cout.tie(0);
//cout << fixed << setprecision(12);
int t = 1;
cin >> t;
while (t--) {
solve();
mp1.clear();
mp2.clear();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3868kb
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: 3852kb
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: 6ms
memory: 3624kb
input:
15134 ][ )( )([[ [)([ )][) ]])( ([]([] ]]))][ [([](] ()[))] ][(]]( ([()[) ()[](( [)([)( ]]([[)]] )[()])]] ))[](([] ](([((]] ))[)][)[ [)])([(] [()[]))[ )][(]()] [[((]()] ((]])[[) ])(](]]) )]]()[]( ([)[])]) [[)[()]( ([[)[[() [[)([])) [)[[)[() ))[(([)( ()][)[](]] [()]([[([[ )[]))][)][ )]([]([(][ [])])(...
output:
Yes Yes Yes Yes Yes Yes No No Yes Yes Yes Yes No Yes No No No Yes No Yes No Yes No No Yes No Yes No No No Yes No No No No Yes No No No No No No No No No Yes No No No No Yes No No No No Yes No No No No Yes No No Yes No No Yes No No No Yes No No No No No No No No No No Yes No No Yes No No No No No No ...
result:
wrong answer expected YES, found NO [7th token]