QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#314333 | #7894. Many Many Heads | Call_me_Eric | WA | 0ms | 3888kb | C++17 | 1.5kb | 2024-01-25 15:40:55 | 2024-01-25 15:40:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
bool stmemory;
namespace Call_me_Eric{
inline int read(){
int x = 0, f = 1;char ch = getchar();
while(ch < '0' || ch > '9'){if(ch == '-') f = -1;ch = getchar();}
while(ch >= '0' && ch <= '9'){x = (x << 1) + (x << 3) + (ch ^ 48);ch = getchar();}
return x * f;
}
const int maxn = 2e5 + 10;
char ch[maxn];int n;
bool getbrack(char ch){if(ch == '[' || ch == ']')return 0;return 1;}
char brack(bool opt, bool lft){if(opt == 0){return lft == 0 ? '[' : ']';}return lft == 0 ? '(' : ')';}
void solve(){
scanf("%s",ch + 1);n = strlen(ch + 1);int cnt = 0;
stack<int> stk;while(stk.size())stk.pop();
for(int i = 1;i <= n;i++){
if(stk.empty()){stk.push(i);continue;}
int x = stk.top();
if(getbrack(ch[x]) == getbrack(ch[i])){
ch[x] = brack(getbrack(ch[x]),0);
ch[i] = brack(getbrack(ch[i]),1);stk.pop();
}
else{stk.push(i);}
cnt += stk.empty();
}
if(!stk.empty() || cnt >= 2){puts("No");return;}
for(int i = 1;i < n;i++)if(ch[i] == ch[i + 1]){puts("No");return;}
puts("Yes");return;
}
void main(){
int T = read();
while(T--){solve();}
return;
}
};
bool edmemory;
signed main(){
auto stclock = clock();
Call_me_Eric::main();
auto edclock = clock();
cerr << (&stmemory - &edmemory) / 1024.0 / 1024.0 << " Mib cost.\n";
cerr << (edclock - stclock) * 1.0 / CLOCKS_PER_SEC << " Sec cost.\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3888kb
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: 3868kb
input:
2 (([([[([ ]]))])]])]
output:
No No
result:
wrong answer expected YES, found NO [1st token]