QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#691871#7894. Many Many HeadswangcqWA 2ms3564kbC++232.2kb2024-10-31 13:17:552024-10-31 13:17:56

Judging History

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

  • [2024-10-31 13:17:56]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3564kb
  • [2024-10-31 13:17:55]
  • 提交

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;
    vector<int> ve;
    for (auto x : s) {
        if (stk.size()) {
            if (stk.top() == check(x)) {
                ve.push_back(check(x));
                stk.pop();
                if (stk.size() == 0) {
                    if (check(x) == pre) {
                        ok = 1;
                    }
                    pre = check(x);
                    cnt ++;
                    for (int j = 0; j + 2 < ve.size(); j ++ ) {
                        if (ve[j] == ve[j + 1] && ve[j] == ve[j + 2]) {
                            ok = 1;
                        }
                    }
                    ve.clear();
                }
            } else {
                stk.push(check(x));
                ve.push_back(check(x));
            }
        } else {
            stk.push(check(x));
            ve.push_back(check(x));
        }
    }
    // cout << stk.size() << " " << cnt << "\n";
    if (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;
}

詳細信息

Test #1:

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

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

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: 2ms
memory: 3564kb

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]