QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#250190#7678. The GameMasterGwxWA 3ms3632kbC++141.9kb2023-11-12 22:40:352023-11-12 22:40:36

Judging History

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

  • [2023-11-12 22:40:36]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3632kb
  • [2023-11-12 22:40:35]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define mp make_pair
typedef long long ll;
const int N=2e5+5;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const ll INF=1e18+3;
#define DEBUG 
#ifdef DEBUG
#define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(x)
#else
#define debug(...) {}
#endif
//debug(n,m);debug("a,b");
//double max:0x7f,0x43 min:0xfe 0x c2  int:0x3f 
//运算符 priority  后缀 前缀 */+- 位移 比较 &^| && || 赋值

void solve()
{
    int n,m;
    cin>>n>>m;
    vector<int> a(n),b(m),ans,res;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<m;i++) cin>>b[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    int k=0,p1=n-1,p2=m-1;
    while(k<=n-m && p2>=0){
        if(a[p1]>b[p2] || k>p1) {
            cout<<-1<<'\n';
            return;
        }
        for(int i=a[p1];i<b[p2];i++) ans.push_back(i);
        k+=b[p2]-a[p1];
        a[p1]=b[p2];
        p2--,p1--;
    }
    //debug(k,p2);
    if(k>n-m || p2>=0){
        cout<<"-1\n";
        return;
    }
    //debug(p1,p2);
    priority_queue<int,vector<int>,greater<int>> q;
    //debug(k);
    p1=0;
    while(k<n-m){
        q.push(a[p1]),k++,p1++;
    }
    //debug(q.size());
    while(!q.empty()){
        int x=q.top();
        q.pop();
        res.push_back(x);
        //debug(x);
        if(q.empty()){
            if(x==b[0]){
                cout<<"-1\n";
                return;
            }
        }
        q.push(x+1);
        q.pop();
    }
    cout<<ans.size()+res.size()<<'\n';
    for(auto i:res) cout<<i<<" ";
    for(auto i:ans) cout<<i<<" ";
    cout<<'\n';
    return;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    #if 1 
        int T; cin>>T; while(T--) solve();
    #else 
        solve();
    #endif 
    return 0; 
}

详细

Test #1:

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

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

result:

ok ok (6 test cases)

Test #2:

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

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

result:

ok ok (7056 test cases)

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 3632kb

input:

5880
4 2
1 1 1 1
1 1
4 2
1 1 1 1
1 2
4 2
1 1 1 1
1 3
4 2
1 1 1 1
1 4
4 2
1 1 1 1
1 5
4 2
1 1 1 1
1 6
4 2
1 1 1 1
1 7
4 2
1 1 1 1
2 2
4 2
1 1 1 1
2 3
4 2
1 1 1 1
2 4
4 2
1 1 1 1
2 5
4 2
1 1 1 1
2 6
4 2
1 1 1 1
2 7
4 2
1 1 1 1
3 3
4 2
1 1 1 1
3 4
4 2
1 1 1 1
3 5
4 2
1 1 1 1
3 6
4 2
1 1 1 1
3 7
4 2
1 1...

output:

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

result:

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