QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#716360#7894. Many Many HeadsliaoyingyuWA 11ms3788kbC++172.4kb2024-11-06 15:00:572024-11-06 15:01:06

Judging History

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

  • [2024-11-06 15:01:06]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:3788kb
  • [2024-11-06 15:00:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;
int A[200100], B[500100], C[500100];
char S[200100];
void ycl() {
}
struct cmp {  //priority_queue
    bool operator()(const int& a, const int& b) {
        return a < b;
    }
};
struct edge {
    int a;
    bool operator<(const edge& x)const {
        return x.a < a;
    }
    edge(int x) { a = x; }
};
bool cmpp(int a, int b) {
    return a > b;
}
int ksm(int a, int b) {
    int ans = 1;
    while (b) {
        if (b & 1)ans = ans * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return ans % MOD;
};
//priority_queue<pair<int, int>, vector<pair<int, int>>, cmp>q;
void solve() {
    string s;
    cin >> s;
    stack<char>st;
    int si = s.size();
    for (int i = 0; i < si; i++) {
        if (s[i] == ')')s[i] = '(';
        else if (s[i] == ']')s[i] = '[';
    }
    map<int, int>mp;
    int now = 0, ma = 0;
    for (int i = 0; i < si; i++) {
        if (st.empty() || st.top() != s[i]) {
            st.push(s[i]);
            if (s[i] == '[') {
                now++;
                ma = max(ma, now);
            }
        }
        else {
            if (!st.empty() && st.top() == '[')now--;
            st.pop();
        }
        if (s[i] == '(') {
            if (mp.find(now) == mp.end())mp[now] = 1;
            else mp[now]++;
        }
    }
    for (auto it : mp) {
        if (it.second > 2) {
            cout << "NO" << endl;
            return;
        }
    }
    mp.clear();
    now = 0, ma = 0;
    for (int i = 0; i < si; i++) {
        if (st.empty() || st.top() != s[i]) {
            st.push(s[i]);
            if (s[i] == '(') {
                now++;
                ma = max(ma, now);
            }
        }
        else {
            if (!st.empty() && st.top() == '(')now--;
            st.pop();
        }
        if (s[i] == '[') {
            if (mp.find(now) == mp.end())mp[now] = 1;
            else mp[now]++;
        }
    }
    for (auto it : mp) {
        if (it.second > 2) {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    //ycl();
    for (int i = 0; i < T; i++) {
        solve();
    }
}

詳細信息

Test #1:

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

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

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: 11ms
memory: 3536kb

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
NO
NO
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

wrong answer expected YES, found NO [43rd token]