QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#647031 | #7678. The Game | ucup-team2526 | WA | 3ms | 3796kb | C++20 | 2.2kb | 2024-10-17 11:09:39 | 2024-10-17 11:09:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define dbg(x...) \
do { \
std::cout << #x << " -> "; \
err(x); \
} while (0)
void err() {
std::cout << std::endl;
}
template<class T, class... Ts>
void err(T arg, Ts &... args) {
std::cout << fixed << setprecision(10) << arg << ' ';
err(args...);
}
void GENSHEN_START() {
int n,m;cin >> n >> m;
vector <int> a(n + 5),b(m + 5);
int cnt1 = 0;
for (int i = 1;i <= n;i++) cin >> a[i];
for (int i = 1;i <= m;i++) cin >> b[i];
sort(a.begin() + 1,a.begin() + 1 + n);
sort(b.begin() + 1,b.begin() + 1 + m);
for (int i = 1;i <= m;i++) cnt1 += (b[i] == b[1]);
int lst = -1;
for (int i = 1;i <= n;i++) {
if (a[i] < b[1]) lst = i;
}
if (lst == -1) {
cout << "-1" << '\n';
return ;
}
vector<int>ans;
int l = 1;
int val = -1,mod = 0,cnt = 0;
for (int i = lst;i >= 1;i--) {
int x = a[i];
if (b[1] - x <= i - l) {
cnt++;
while (x != b[1]) {
ans.push_back(x);
x++;
l++;
}
}
else {
val = x;
mod = i - l + 1;
break;
}
}
vector<int>c;
int cnt2 = 0;
while (cnt) {
c.push_back(b[1]);
cnt--;
cnt2++;
}
for (int i = 1;i <= n;i++) {
if (a[i] >= b[1]) c.push_back(a[i]);
cnt2 += (a[i] == b[1]);
}
//for (auto i : c) dbg(i);
//dbg(mod);
int len = c.size();
if (cnt2 < cnt1) {
cout << "-1" << '\n';
return ;
}
if (len - (cnt2 - cnt1) > m) {
cout << "-1" << '\n';
return ;
}
int all = len - m,sum = 0;
for (int i = len - m;i < len;i++) {
if (c[i] > b[i - len + m + 1]) {
cout << "-1" << '\n';
return ;
}
sum += b[i - len + m + 1] - c[i];
}
if (sum >= all && sum <= all + mod) {
for (int i = 1;i <= mod - (sum - all);i++) {
ans.push_back(val);
val++;
}
for (int i = len - m;i < len;i++) {
while (c[i] < b[i - len + m + 1]) {
ans.push_back(c[i]);
c[i]++;
}
}
cout << ans.size() << '\n';
for (auto i : ans) cout << i << ' ';
cout << '\n';
}
else {
cout << "-1" << '\n';
}
}
signed main()
{
ios::sync_with_stdio(false);cin.tie(nullptr);
int T = 1;
cin >> T;
while (T--) GENSHEN_START();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
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 4 4 3 5 1 2 3 1 2 2 1 1 -1
result:
ok ok (6 test cases)
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 3796kb
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 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -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:
wrong answer Jury has answer but participant has not (test case 2)