QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#257977#7678. The Game8BQube#WA 31ms3836kbC++142.1kb2023-11-19 14:08:522023-11-19 14:08:52

Judging History

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

  • [2023-11-19 14:08:52]
  • 评测
  • 测评结果:WA
  • 用时:31ms
  • 内存:3836kb
  • [2023-11-19 14:08:52]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define SZ(a) ((int)a.size())

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> A(n), B(m);
    multiset<int> st;
    for (int i = 0; i < n; i++)
        cin >> A[i], st.insert(A[i]);
    for (int i = 0; i < m; i++)
        cin >> B[i];   
    sort(ALL(A), greater<int>());
    sort(ALL(B), greater<int>());
    A.resize(m);
    int quota = n - m;
    vector<int> v;
    for (int i = 0; i < m; i++)
        if (A[i] > B[i] || B[i] - A[i] > quota) {
            cout << -1 << "\n";
            return;
        }
        else {
            // cerr << A[i] << " " << B[i] << endl;
            for (int x = A[i]; x < B[i]; x++) {
                v.pb(x); 
                quota--;
            }
        }
    sort(ALL(v));
    // for (int i = 0; i < SZ(v); i++)
    //     cerr << v[i] << " \n"[i + 1 == SZ(v)];
    vector<int> tmp;
    for (int i = 0; i < quota; i++) {
        int x = *st.begin();
        st.erase(st.begin());
        st.insert(x + 1);
        st.erase(st.begin());
        tmp.pb(x);
        // cerr << "tmp " << x << endl;
    }
    for (int i = 0; i < SZ(v); i++) {
        if (st.find(v[i]) == st.end()) {
            cout << -1 << "\n";
            return;
        }
        st.erase(st.lower_bound(v[i]));
        st.insert(v[i] + 1);
        st.erase(st.begin());
    }
    vector<int> C;
    for (int x : st)
        C.pb(x);
    reverse(ALL(B));
    // for (int i = 0; i < SZ(C); i++)
    //     cerr << C[i] << " \n"[i + 1 == SZ(C)];
    if (B != C) {
        cout << -1 << "\n";
        return;
    }
    for (int x : v)
        tmp.pb(x);
    cout << n - m << "\n";
    for (int i = 0; i < n - m; i++)
        cout << tmp[i] << " \n"[i + 1 == n - m];
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    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: 3756kb

input:

6
5 3
1 2 2 3 3
2 3 4
4 2
1 2 2 4
2 4
5 2
2 3 3 4 4
5 5
6 1
1 1 1 1 1 1
4
4 2
1 1 1 2
2 2
4 1
1 1 1 1
2

output:

2
1 3
-1
3
2 4 4
5
1 1 1 2 3
2
1 1
-1

result:

ok ok (6 test cases)

Test #2:

score: 0
Accepted
time: 4ms
memory: 3792kb

input:

7056
4 3
1 1 1 1
1 1 1
4 3
1 1 1 1
1 1 2
4 3
1 1 1 1
1 1 3
4 3
1 1 1 1
1 1 4
4 3
1 1 1 1
1 1 5
4 3
1 1 1 1
1 1 6
4 3
1 1 1 1
1 2 2
4 3
1 1 1 1
1 2 3
4 3
1 1 1 1
1 2 4
4 3
1 1 1 1
1 2 5
4 3
1 1 1 1
1 2 6
4 3
1 1 1 1
1 3 3
4 3
1 1 1 1
1 3 4
4 3
1 1 1 1
1 3 5
4 3
1 1 1 1
1 3 6
4 3
1 1 1 1
1 4 4
4 3
1 1...

output:

-1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
2
-1
-1
-1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok ok (7056 test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1
-1
-1
-1
-1
3
1 1 2
3
1 2 3
3
2 3 4
-1
-1
-1
-1
-1
3
1 1 2
3
1 1 3
3
1 3 4
3
3 4 5
-1
-1
-1
-1
-1
3
1 1 2
3
1 1 4
3
1 4 5
3
4 5 6
-1
-1
-1
-1
-1
3
1 1 2
3
1 1 5
3
1 5 6
3
5 6 7
-1
-1
-1
-1
-1
3
1 1 2
3
1 1 6
3
1 6 7
-1
-1
-1
-1
-1
-1
3
1 1 2
3
1 1 7
-1
-1
-1
-1
-1
-1
-1
3...

result:

ok ok (2640 test cases)

Test #5:

score: 0
Accepted
time: 9ms
memory: 3536kb

input:

14112
5 3
1 1 1 1 1
1 1 1
5 3
1 1 1 1 1
1 1 2
5 3
1 1 1 1 1
1 1 3
5 3
1 1 1 1 1
1 1 4
5 3
1 1 1 1 1
1 1 5
5 3
1 1 1 1 1
1 1 6
5 3
1 1 1 1 1
1 2 2
5 3
1 1 1 1 1
1 2 3
5 3
1 1 1 1 1
1 2 4
5 3
1 1 1 1 1
1 2 5
5 3
1 1 1 1 1
1 2 6
5 3
1 1 1 1 1
1 3 3
5 3
1 1 1 1 1
1 3 4
5 3
1 1 1 1 1
1 3 5
5 3
1 1 1 1 1
...

output:

-1
-1
2
1 2
-1
-1
-1
2
1 1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
2 3
-1
-1
-1
2
1 2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
1 1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok ok (14112 test cases)

Test #6:

score: 0
Accepted
time: 3ms
memory: 3536kb

input:

5292
5 2
1 1 1 1 1
1 1
5 2
1 1 1 1 1
1 2
5 2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 3
4
1 1 3 4
4
1 3 4 5
4
3 4 5 6
-1
-1
-1
4
1 1 2 3
4
1 1 2 4
4
1 1 4 5
4
1 4 5 6
-1
-1
-1
-1
4
1 1 2 3
4
1 1 2 5
4
1 1 5 6
-1
-1
-1
-1
-1
4
1 1 2 3
4
1 1 2 6
-1
-1
-1
-1
-1
-1
4
1 1 2 3
-1
-1
...

result:

ok ok (3234 test cases)

Test #8:

score: 0
Accepted
time: 2ms
memory: 3608kb

input:

8820
5 4
1 1 1 1 1
1 1 1 1
5 4
1 1 1 1 1
1 1 1 2
5 4
1 1 1 1 1
1 1 1 3
5 4
1 1 1 1 1
1 1 1 4
5 4
1 1 1 1 1
1 1 1 5
5 4
1 1 1 1 1
1 1 2 2
5 4
1 1 1 1 1
1 1 2 3
5 4
1 1 1 1 1
1 1 2 4
5 4
1 1 1 1 1
1 1 2 5
5 4
1 1 1 1 1
1 1 3 3
5 4
1 1 1 1 1
1 1 3 4
5 4
1 1 1 1 1
1 1 3 5
5 4
1 1 1 1 1
1 1 4 4
5 4
1 1 1...

output:

-1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
2
-1
-1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok ok (8820 test cases)

Test #9:

score: 0
Accepted
time: 17ms
memory: 3620kb

input:

26460
6 5
1 1 1 1 1 1
1 1 1 1 1
6 5
1 1 1 1 1 1
1 1 1 1 2
6 5
1 1 1 1 1 1
1 1 1 1 3
6 5
1 1 1 1 1 1
1 1 1 1 4
6 5
1 1 1 1 1 1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1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok ok (50000 test cases)

Test #11:

score: 0
Accepted
time: 16ms
memory: 3836kb

input:

25872
6 3
1 1 1 1 1 1
1 1 1
6 3
1 1 1 1 1 1
1 1 2
6 3
1 1 1 1 1 1
1 1 3
6 3
1 1 1 1 1 1
1 1 4
6 3
1 1 1 1 1 1
1 1 5
6 3
1 1 1 1 1 1
1 1 6
6 3
1 1 1 1 1 1
1 2 2
6 3
1 1 1 1 1 1
1 2 3
6 3
1 1 1 1 1 1
1 2 4
6 3
1 1 1 1 1 1
1 2 5
6 3
1 1 1 1 1 1
1 2 6
6 3
1 1 1 1 1 1
1 3 3
6 3
1 1 1 1 1 1
1 3 4
6 3
1 1 ...

output:

-1
-1
-1
3
1 2 3
-1
-1
-1
3
1 1 2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
3
1 1 1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
3
2 3 4
-1
-1
-1
3
1 2 3
-1
-1
3
1 2 2
-1
-1
-1
-1
-1
-1
-1
-1
-1
3
1 1 1
3
1 1 2
-1
-1
-1
-1
-1
-1
-1
-1...

result:

ok ok (25872 test cases)

Test #12:

score: 0
Accepted
time: 15ms
memory: 3604kb

input:

25872
6 2
1 1 1 1 1 1
1 1
6 2
1 1 1 1 1 1
1 2
6 2
1 1 1 1 1 1
1 3
6 2
1 1 1 1 1 1
1 4
6 2
1 1 1 1 1 1
1 5
6 2
1 1 1 1 1 1
1 6
6 2
1 1 1 1 1 1
1 7
6 2
1 1 1 1 1 1
2 2
6 2
1 1 1 1 1 1
2 3
6 2
1 1 1 1 1 1
2 4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
-1
-1
5
1 1 1 2 3
5
1 1 1 2 5
5
1 1 ...

result:

wrong answer Jury has answer but participant has not (test case 3)