QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#544226#7678. The Gameucup-team2179#WA 0ms3536kbC++202.0kb2024-09-02 13:16:112024-09-02 13:16:12

Judging History

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

  • [2024-09-02 13:16:12]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3536kb
  • [2024-09-02 13:16:11]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define pii pair<int, int>
using namespace std;
const int maxn = 1e5 + 10;
const int mod = 998244353;

void solve(){
    int n, m;
    cin >> n >> m;
    multiset<int> a, b;
    for (int i = 0; i < n;i++){
        int u;
        cin >> u;
        a.insert(u);
    }
    for (int i = 0; i < m;i++){
        int u;
        cin >> u;
        b.insert(u);
    }
    map<int, int> mp;
    for(auto p:a){
        if(b.count(p))
            mp[p] = min(b.count(p), a.count(p));
    }
    for(auto [v,cnt]:mp){
        for (int i = 0; i < cnt;i++){
            a.erase(a.find(v));
            b.erase(b.find(v));
        }
    }
    int mi = *b.begin();
//    cout << a.size() << " SS " << b.size() << "\n";
    int flag = 1;
    vector<int> ans;
    for (int i = 0; i < n - m;i++){
        if(b.empty()){
            int u = *(a.begin());
            if(u>=mi)
                flag = 0;
            ans.pb(u);
            a.erase(a.find(u));
            a.insert(u + 1);
            int k = *a.begin();
            a.erase(a.find(k));
        }
        else {
            int u = *(a.rbegin());
            ans.pb(u);
            a.erase(a.find(u));
            if(b.count(u+1))
                b.erase(b.find(u + 1));
            else
                a.insert(u + 1);
            int k = *a.begin();
            a.erase(a.find(k));
        }
    }
//    cout << a.size() << " " << b.size() << "\n";
    if(b.size()||a.size()||(flag==0)){
        cout <<-1<<"\n";
    }
    else {
        cout << ans.size() <<"\n";
        assert((int)ans.size()==n-m);
        for (int i = 0; i < n - m;i++){
            cout << ans[i];
            if(i!=n-m-1)
            cout << " ";
        }
            cout << '\n';
    }
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

详细

Test #1:

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

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

result:

wrong answer Wrong answer, the final sequence does not equal to B (test case 1)