QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#647095 | #7678. The Game | ucup-team2526 | WA | 3ms | 3628kb | C++20 | 2.2kb | 2024-10-17 11:38:47 | 2024-10-17 11:38:47 |
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,ok = 0;
for (int i = 1;i <= n;i++) {
if (a[i] < b[1]) lst = i;
}
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 < m) {
cout << "-1" << '\n';
return ;
}
int all = len - m,sum = 0;
for (int i = cnt1 + (len - m);i < len;i++) {
int ppp = i - (cnt1 + (len - m)) + 1 + cnt1;
//dbg(i,ppp);
if (c[i] > b[i - (cnt1 + (len - m)) + 1 + cnt1]) {
cout << "-1" << '\n';
return ;
}
sum += b[i - (cnt1 + (len - m)) + 1 + cnt1] - c[i];
}
//dbg(sum,all,mod);
if (sum >= all && sum <= all + mod) {
for (int i = 1;i <= mod - (sum - all);i++) {
ans.push_back(val);
val++;
}
for (int i = cnt1 + (len - m);i < len;i++) {
while (c[i] < b[i - (cnt1 + (len - m)) + 1 + cnt1]) {
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
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: 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:
wrong answer Wrong answer, the final sequence does not equal to B (test case 339)