QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#250585 | #7678. The Game | Cu_OH_2 | WA | 4ms | 3792kb | C++14 | 2.8kb | 2023-11-13 13:39:17 | 2023-11-13 13:39:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m;
int back(multiset<int>& ms) { return *ms.rbegin(); }
int front(multiset<int>& ms) { return *ms.begin(); }
void erase(multiset<int>& ms, int x) { ms.erase(ms.find(x)); }
void pop_back(multiset<int>& ms) { ms.erase(prev(ms.end())); }
void add_front(multiset<int>& ms)
{
int x = *ms.begin();
ms.erase(ms.begin());
ms.insert(x + 1);
}
void pop_front(multiset<int>& ms) { ms.erase(ms.begin()); }
void solve()
{
cin >> n >> m;
multiset<int> ms1, ms2;
for (int i = 1; i <= n; ++i)
{
int x;
cin >> x;
ms1.insert(x);
}
for (int i = 1; i <= m; ++i)
{
int x;
cin >> x;
ms2.insert(x);
}
multiset<int> ms;
vector<int> rec;
while (ms2.size())
{
if (back(ms1) > back(ms2))
{
cout << "-1\n";
return;
}
for (int i = back(ms1); i < back(ms2); ++i)
{
rec.push_back(i);
if (rec.size() > n - m)
{
cout << "-1\n";
return;
}
}
ms.insert(back(ms1));
pop_back(ms1);
pop_back(ms2);
}
sort(rec.begin(), rec.end());
vector<int> ans;
int p = 0;
// for (auto e : ms1) cerr << e << ' ';
// cerr << endl;
// for (auto e : ms) cerr << e << ' ';
// cerr << endl;
while (ms1.size())
{
if (ms1.size() > rec.size() - p)
{
while (front(ms1) == front(ms) && ms1.count(front(ms1)) == 1)
{
if (p >= rec.size())
{
cout << "-1\n";
return;
}
ans.push_back(rec[p]);
erase(ms, rec[p]);
ms.insert(rec[p] + 1);
p++;
pop_front(ms1);
}
ans.push_back(front(ms1));
add_front(ms1);
pop_front(ms1);
}
else
{
ans.push_back(rec[p]);
erase(ms, rec[p]);
ms.insert(rec[p] + 1);
p++;
if (front(ms1) > front(ms))
{
cout << "-1\n";
return;
}
pop_front(ms1);
}
// for (auto e : ms1) cerr << e << ' ';
// cerr << "| ";
// for (auto e : ms) cerr << e << ' ';
// cerr << endl;
}
cout << ans.size() << '\n';
for (auto e : ans) cout << e << ' ';
cout << '\n';
return;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
cin >> T;
while (T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3792kb
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: 3604kb
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: 3ms
memory: 3600kb
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 1 2 -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 1 3 -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)