QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#298670#7894. Many Many Headsucup-team045#WA 0ms3804kbC++201.4kb2024-01-06 13:57:102024-01-06 13:57:12

Judging History

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

  • [2024-01-06 13:57:12]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3804kb
  • [2024-01-06 13:57:10]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<array>
using namespace std;
using LL = long long;

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int T;
    cin >> T;
    while(T--){
        string s;
        cin >> s;
        const int n = s.size();
        for(auto &c : s){
            if (c == ')') c = '(';
            if (c == ']') c = '[';
        }
        s = " " + s;
        vector<array<int, 2> > pre(n + 1);
        for(int i = 1; i <= n; i++){
            pre[i] = pre[i - 1];
            pre[i][(s[i] != '(')] = i;
        }

        vector<int> dep(n + 1);
        auto solve = [&](auto &&solve, int l, int r, char last, int lastdep) -> void {
            if (l > r) return;
            int k = pre[r][s[l] != '('];
            if (s[l] == last){
                dep[l] = dep[k] = lastdep + 1;
            }
            else{
                dep[l] = dep[k] = 1;
            }
            solve(solve, l + 1, k - 1, s[l], dep[l]); 
            solve(solve, k + 1, r, last, lastdep);
        };

        solve(solve, 1, n, ' ', 0);

        bool ok = true;
        for(int i = 1; i + 1 <= n; i++){
            if (dep[i] >= 2){
                ok = false;
                break;
            }
        }
        cout << (ok ? "Yes" : "No") << '\n';
    }

}

詳細信息

Test #1:

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

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: -100
Wrong Answer
time: 0ms
memory: 3804kb

input:

2
(([([[([
]]))])]])]

output:

No
No

result:

wrong answer expected YES, found NO [1st token]