QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#643663#7894. Many Many HeadsLeft0807WA 0ms3600kbC++201.9kb2024-10-15 22:45:312024-10-15 22:45:33

Judging History

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

  • [2024-10-15 22:45:33]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3600kb
  • [2024-10-15 22:45:31]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int long long
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update>;


int INF = 1e18; 
const int MOD = 998244353;
const int N = 5e5 + 10;
const int LOG = 20;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int a[N];

void solve(){
    string s;
    cin >> s;
    int n = s.size();

    string t = "", st = "";

    for(char& c : s){
        if(c == ')') c = '(';
        if(c == ']') c = '[';

        if(st.back() == c){
            st.pop_back();
            if(c == '(') c = ')';
            else c = ']';
        } else{
            st.push_back(c);
        }
    }

    s = ' ' + s + ' ';
    vector<int> st1, st2;
    vector<int> pos(n+1);

    for(int i = 1; i <= n; i++){
        if(s[i] == '(') st1.push_back(i);
        else if(s[i] == '[') st2.push_back(i);
        else if(s[i] == ')'){
            pos[st1.back()] = i;
            st1.pop_back();
        } else{
            pos[st2.back()] = i;
            st2.pop_back();
        }
    }

    bool ok = true;

    for(int i = 1; i <= n; i++){
        if(s[i] == ')' && s[i+1] == '(') ok = false;
        if(s[i] == ']' && s[i+1] == '[') ok = false;
        if(pos[i] && s[i] == ')' && s[pos[i] + 1] == '(') ok = false;
        if(pos[i] && s[i] == ']' && s[pos[i] + 1] == '[') ok = false;
    }

    if(ok) cout << "Yes\n";
    else cout << "No\n";
}


int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int tt;
    cin >> tt;

    while(tt--){
        solve();
    }
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3600kb

input:

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

output:

Yes
No
Yes
Yes
Yes
No

result:

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