QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#363247#7894. Many Many HeadsOobugoORE 0ms0kbC++201.4kb2024-03-23 19:56:392024-03-23 19:56:40

Judging History

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

  • [2024-03-23 19:56:40]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-03-23 19:56:39]
  • 提交

answer

#include <bits/stdc++.h>

#define x first
#define y second

typedef long long ll;

int get(char c) {
    if (c == '(' || c == ')') return 1;
    else if (c == '[' || c == ']')  return 2;
}

void solve() {
    std::string s;
    std::cin >> s;
    int n = s.size();
    std::vector<char> st(1, '#');
    int now_dep = 1;
    std::vector<int> dep;
    std::vector<int> f;
    for (int i = 0; i < n; i++) {
        if (get(s[i]) == get(st.back())){
            now_dep--;
            dep.push_back(now_dep);
            f.push_back(get(s[i]));
            st.pop_back();
        } else {
            now_dep++;
            st.push_back(s[i]);
        }
    }
    int mx = *(std::max_element(dep.begin(), dep.end()));
    std::vector<int> pre(mx + 1, 0);
    std::vector<int> num(mx + 1, 0);
    for (int i = 0; i < dep.size(); i++) {
        if (pre[dep[i]] == f[i] || num[dep[i]] == 2) {
            std::cout << "No\n";
            return;
        }
        pre[dep[i]] = f[i];
        num[dep[i]]++;
    }
    if (st.size() == 1) {
        std::cout << "Yes\n";
    } else {
        std::cout << "No\n";
    }
}

int main(){

#ifdef Onlion_Judge
    freopen("IO/input.in", "r", stdin);
    freopen("IO/output.out", "w", stdout);
    // freopen("E:\\save work\\data\\4.in", "w", stdout);
#endif

    int t = 1;
    std::cin >> t;
    while (t--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

6
))
((()
[()]
()[()]()
([()])
([])([])

output:


result: