QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#690709#7894. Many Many HeadswangcqWA 4ms3548kbC++232.1kb2024-10-31 01:03:242024-10-31 01:03:24

Judging History

你现在查看的是最新测评结果

  • [2024-10-31 01:03:24]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:3548kb
  • [2024-10-31 01:03:24]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const double eps = 1e-10;
const int N = 100010;
const double PII = acos(-1);
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f;
// int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
// int dir[8][2] = {{1, 0}, {1, -1}, {1, 1}, {0, 1}, {0, -1}, {-1, 1}, {-1, 0}, {-1, -1}};
// std::mt19937 rng {std::chrono::steady_clock::now().time_since_epoch().count()};

template <typename T>
void debug(T x) {
    cerr << x << '\n';
}

template <typename T, typename... Args>
void debug(T x, Args... args) {
    cerr << x << ' ';
    debug(args...);
}

void solve() {
    string s;
    cin >> s;

    auto check = [&](char c) {
        if (c == '(' || c == ')') return 1;
        else return 0;
    };

    stack<int> stk;
    int cnt = 0, pre = -1, ok = 0;
    int pree = -1, cntt = 0;
    for (auto x : s) {
        if (stk.size()) {
            if (stk.top() == check(x)) {
                stk.pop();
                if (stk.size() == 0) {
                    if (check(x) == pre) {
                        ok = 1;
                    }
                    pre = check(x);
                    cnt ++;
                    pree = -1;
                    cntt = 0;
                } else {
                    if (check(x) == pree) {
                        ok = 1;
                    }
                    pree = check(x);
                    cntt ++;
                    if (cntt > 2) {
                        ok = 1;
                    }
                }
            } else {
                stk.push(check(x));
            }
        } else {
            stk.push(check(x));
        }
    }
    // debug((int)stk.size(), cnt, ok);
    if ((int)stk.size() || cnt > 2 || ok) {
        cout << "No" << "\n";
    } else {
        cout << "Yes" << "\n";
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    cin >> T;
    while (T -- ) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3548kb

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: 3524kb

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: 4ms
memory: 3536kb

input:

15134
][
)(
)([[
[)([
)][)
]])(
([]([]
]]))][
[([](]
()[))]
][(]](
([()[)
()[]((
[)([)(
]]([[)]]
)[()])]]
))[](([]
](([((]]
))[)][)[
[)])([(]
[()[]))[
)][(]()]
[[((]()]
((]])[[)
])(](]])
)]]()[](
([)[])])
[[)[()](
([[)[[()
[[)([]))
[)[[)[()
))[(([)(
()][)[](]]
[()]([[([[
)[]))][)][
)]([]([(][
[])])(...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
No
Yes
No
Yes
No
No
Yes
No
No
Yes
No
No
Yes
No
No
Yes
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
Yes
No
No
No
No
Yes
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No...

result:

wrong answer expected YES, found NO [20th token]