QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#716377#7894. Many Many HeadsliaoyingyuWA 8ms3560kbC++172.5kb2024-11-06 15:04:062024-11-06 15:04:07

Judging History

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

  • [2024-11-06 15:04:07]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:3560kb
  • [2024-11-06 15:04:06]
  • 提交

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++) {
        if (i == 42) {
            string s;
            cin >> s;
            cout << s;
        }
        solve();

    }
}

详细

Test #1:

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

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

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: 8ms
memory: 3508kb

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

result:

wrong output format YES or NO expected, but )]](])[](]NO found [43rd token]