QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#847 | #576668 | #7894. Many Many Heads | hzjoiineg | Laffey | Failed. | 2024-09-20 10:09:11 | 2024-09-20 10:09:12 |
Details
Extra Test:
Accepted
time: 462ms
memory: 5148kb
input:
10 ])])[)[(])]([(])]([)[)[)](](])[([([)])]([([(]([(](])])](])[([)](])](](](])[)]([([(]([)]([(])[)[)[(])]([(]([([)](])](])](])[)[)[(](](](]([([([)])](])])]([(])[)](])[([([(])](])[([(])[)[([)]([(])])]([(])[)[([([(](])])[(](](])[)](])](])[)[(])[(](])])](](]([)](])[)[)])[)[([)])])])])[(](])[)[)]([(])[(]...
output:
Yes No Yes No Yes No Yes No Yes No
result:
ok 10 token(s): yes count is 5, no count is 5
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#576668 | #7894. Many Many Heads | Laffey | AC ✓ | 796ms | 5152kb | C++20 | 1006b | 2024-09-19 21:29:51 | 2024-09-19 21:29:51 |
answer
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
const int MAXN = 1e5 + 10;
int st[MAXN], top;
int v[MAXN][2];
char s[MAXN];
inline void init()
{
top = 0;
for (int i = 1; st[i] != -1; i++) {
v[i][0] = v[i][1] = 0;
st[i] = -1;
}
}
inline int type(const char &c)
{
return (c == '[' || c == ']') ? 1 : 0;
}
inline bool check()
{
for (int i = 0; i < strlen(s); i++) {
int t = type(s[i]);
if (st[top] == t) {
v[top][t]++;
if (v[top][t] == 2) return false;
top--;
}
else {
st[++top] = t;
}
}
return true;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("./in", "r", stdin);
#endif
st[MAXN - 1] = st[0] = -1;
int t;
scanf("%d", &t);
while (t--) {
init();
scanf("%s", s);
printf("%s\n", (check() ? "Yes" : "No"));
}
return 0;
}