QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#671718 | #7894. Many Many Heads | wsy_jim# | WA | 7ms | 3868kb | C++14 | 1.5kb | 2024-10-24 14:10:49 | 2024-10-24 14:10:49 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdlib>
#include<ctime>
#include<bitset>
#include<vector>
#include<climits>
#include<iomanip>
using namespace std;
template<typename T>
inline void read(T &x){
x=0;bool flg=0;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') flg=1;
for(;isdigit(c);c=getchar()) x=x*10+(c^48);
if(flg) x=-x;
}
int n;
const int N = 1e6 + 10;
string s;
int a[N];
stack<int> stk;
int main(){
int T;
cin >> T;
while (T--)
{
cin >> s;
int n = s.size();
for (int i = 0; i < n; i++)
{
if (s[i] == '(' || s[i] == ')')
a[i + 1] = 0;
else
a[i + 1] = 1;
}
while (!stk.empty())
stk.pop();
int num0 = 0, num1 = 0;
for (int i = 1; i <= n; i++)
{
if (stk.empty() || stk.top() != a[i])
stk.push(a[i]);
else {
stk.pop();
if (stk.empty()) {
if (a[i] == 0)
num0++;
else
num1++;
}
}
}
if (stk.empty() && ((num0 == 0 && num1 == 1) || (num0 == 1 && num1 == 0) || (num0 == 1 && num1 == 1)))
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3832kb
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: 3652kb
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: 7ms
memory: 3868kb
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 Yes Yes Yes No No No Yes No No No No Yes No No No Yes Yes Yes No Yes No No No No No No Yes No No No No No No No No No No Yes Yes No No No No No No...
result:
wrong answer expected NO, found YES [45th token]