QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#691921#7894. Many Many HeadswangcqWA 5ms3652kbC++232.0kb2024-10-31 13:26:002024-10-31 13:26:01

Judging History

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

  • [2024-10-31 13:26:01]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:3652kb
  • [2024-10-31 13:26:00]
  • 提交

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;
    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 ++;
                }
            } else {
                stk.push(check(x));
            }
        } else {
            stk.push(check(x));
        }
    }
    int len = (int)s.length() - 3;
    for (int i = 0; i <= len; i ++ ) { 
        if ((check(s[i]) == check(s[i + 1])) && (check(s[i + 2]) == check(s[i + 1]))) {
            ok = 1;
        }
    }
    // 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: 3588kb

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

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: 5ms
memory: 3652kb

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]