QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#806665#9873. Last Chance: Threads of DespairPessimismWA 1ms3868kbC++234.8kb2024-12-09 13:41:132024-12-09 13:41:13

Judging History

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

  • [2024-12-09 13:41:13]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3868kb
  • [2024-12-09 13:41:13]
  • 提交

answer

#include<bits/stdc++.h>

#define endl "\n"
// #define int long long

using namespace std;

using i64 = long long;
using u64 = unsigned long long;

constexpr int N = 2e5 + 10, M = 2e6 + 10;
constexpr int P = 998244353;
constexpr int INF = 1e9;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> h(n), g(m);
    priority_queue<int, vector<int>, greater<>> used;
    priority_queue<int, vector<int>, greater<>> emy;
    priority_queue<int, vector<int>, greater<>> my;
    bool has = false;
    int cnt = 0;
    bool first = false;
    int attack = 0;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
        if (h[i] == 1) {
            if (!first) {
                attack++;
            }
            has = true;
            first = true;
            cnt++;
        } else {
            my.push(h[i]);
        }
    }
    for (int i = 0; i < m; i++) {
        cin >> g[i];
        emy.push(g[i]);
    }
    while (!emy.empty()) {
        if (!has) {
            while (!emy.empty() && emy.top() > 1 && !my.empty()) {
                auto top = emy.top();
                emy.pop();
                emy.push(top - 1);

                used.push(my.top() - 1);
                my.pop();
            }
            if (!emy.empty() && emy.top() <= 1) {
                if (!my.empty()) {
                    has = true;
                    first = true;
                    cnt++;
                    used.push(my.top() - 1);
                    my.pop();
                    emy.pop();
                } else {
                    cout << "NO\n";
                    return;
                }
            } else {
                cout << "NO\n";
                return;
            }
        } else if (!first) {
            if (!emy.empty() && emy.top() <= 1) {
                cnt++;
                emy.pop();
            } else if (my.size() > 1 && my.top() <= 1) {
                cnt++;
                attack++;
                my.pop();
            } else if (!used.empty() && used.top() <= 1) {
                cnt++;
                used.pop();
            } else {
                while (!emy.empty() && emy.top() > 1 && attack > 0) {
                    auto top = emy.top();
                    emy.pop();
                    emy.push(top - 1);
                    attack--;
                }
                while (!emy.empty() && emy.top() > 1 && !my.empty()) {
                    auto top = emy.top();
                    emy.pop();
                    emy.push(top - 1);

                    used.push(my.top() - 1);
                    my.pop();
                }
                if (!emy.empty() && emy.top() <= 1) {
                    cnt++;
                    emy.pop();
                } else {
                    if (my.empty()) {
                        break;
                    }
                }
            }
            first = true;
        } else {
            if (!emy.empty() && emy.top() <= cnt) {
                cnt++;
                emy.pop();
            } else if (my.size() > 1 && my.top() <= cnt) {
                cnt++;
                attack++;
                my.pop();
            } else if (!used.empty() && used.top() <= cnt) {
                cnt++;
                used.pop();
            } else {
                while (!emy.empty() && emy.top() > cnt && attack > 0) {
                    auto top = emy.top();
                    emy.pop();
                    emy.push(top - 1);
                    attack--;
                }
                while (!emy.empty() && emy.top() > cnt && !my.empty()) {
                    auto top = emy.top();
                    emy.pop();
                    emy.push(top - 1);

                    used.push(my.top() - 1);
                    my.pop();
                }
                if (!emy.empty() && emy.top() <= cnt) {
                    cnt++;
                    emy.pop();
                } else {
                    if (my.empty()) {
                        break;
                    }
                }
            }
        }
    }
    while (!used.empty() && used.top() <= cnt) {
        cnt++;
        used.pop();
    }
    while (!emy.empty() && emy.top() <= cnt) {
        cnt++;
        emy.pop();
    }
    while (!emy.empty() && emy.top() > cnt && attack > 0) {
        auto top = emy.top();
        emy.pop();
        emy.push(top - 1);
        attack--;
    }
    while (!emy.empty() && emy.top() <= cnt) {
        cnt++;
        emy.pop();
    }
    cout << (emy.empty() && has ? "YES\n" : "NO\n");
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T;
    cin >> T;
    while (T--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
3 2
1 1 4
2 6
3 2
1 1 4
2 7
2 1
100 100
2

output:

YES
NO
YES

result:

ok 3 token(s): yes count is 2, no count is 1

Test #2:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

3
7 1
1 1 1 1 1 1 1
9
5 2
3 4 5 6 7
1 6
5 3
3 4 5 6 7
1 5 7

output:

NO
NO
YES

result:

ok 3 token(s): yes count is 1, no count is 2

Test #3:

score: 0
Accepted
time: 0ms
memory: 3864kb

input:

4
1 1
1
1
1 1
1
2
1 1
2
1
1 1
2
2

output:

YES
YES
YES
NO

result:

ok 4 token(s): yes count is 3, no count is 1

Test #4:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

18
1 2
1
1 1
1 2
1
2 1
1 2
1
1 3
1 2
1
2 2
1 2
1
3 2
1 2
1
3 3
1 2
2
1 1
1 2
2
1 2
1 2
2
1 3
1 2
2
2 2
1 2
2
2 3
1 2
2
3 3
1 2
3
1 1
1 2
3
1 2
1 2
3
1 3
1 2
3
2 2
1 2
3
3 2
1 2
3
3 3

output:

YES
YES
YES
YES
NO
NO
YES
YES
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO

result:

ok 18 token(s): yes count is 7, no count is 11

Test #5:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

18
2 1
1 1
1
2 1
1 1
2
2 1
1 1
3
2 1
1 2
1
2 1
2 1
2
2 1
2 1
3
2 1
1 3
1
2 1
1 3
2
2 1
3 1
3
2 1
2 2
1
2 1
2 2
2
2 1
2 2
3
2 1
2 3
1
2 1
3 2
2
2 1
2 3
3
2 1
3 3
1
2 1
3 3
2
2 1
3 3
3

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
NO
YES
YES
NO

result:

ok 18 token(s): yes count is 15, no count is 3

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 3868kb

input:

525
2 3
1 1
1 1 1
2 3
1 1
1 2 1
2 3
1 1
1 3 1
2 3
1 1
1 4 1
2 3
1 1
5 1 1
2 3
1 1
2 2 1
2 3
1 1
3 1 2
2 3
1 1
1 2 4
2 3
1 1
2 1 5
2 3
1 1
3 3 1
2 3
1 1
4 3 1
2 3
1 1
3 5 1
2 3
1 1
4 4 1
2 3
1 1
4 5 1
2 3
1 1
1 5 5
2 3
1 1
2 2 2
2 3
1 1
2 3 2
2 3
1 1
2 2 4
2 3
1 1
2 5 2
2 3
1 1
3 2 3
2 3
1 1
3 2 4
2 ...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
NO
YES
NO
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
Y...

result:

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