QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#847#576668#7894. Many Many HeadshzjoiinegLaffeyFailed.2024-09-20 10:09:112024-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

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#576668#7894. Many Many HeadsLaffeyAC ✓796ms5152kbC++201006b2024-09-19 21:29:512024-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;
}