QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#383451 | #7678. The Game | Giga_Cronos# | WA | 3ms | 3804kb | C++23 | 2.7kb | 2024-04-09 14:21:06 | 2024-04-09 14:21:07 |
Judging History
answer
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops",
// "omit-frame-pointer", "inline") #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma,tune=native")
// #pragma GCC option("arch=native", "no-zero-upper") // Enable AVX
/// UH Top
#include <bits/stdc++.h>
#define db(x) cerr << #x << ':' << (x) << '\n';
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
// #define int ll
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
// typedef __int128_t int128;
typedef pair<ll, ll> pii;
typedef pair<ld, ll> pdi;
typedef pair<ld, ld> pdd;
typedef pair<ld, pdd> pdp;
typedef pair<string, ll> psi;
typedef pair<ll, string> pls;
typedef pair<string, string> pss;
typedef pair<ll, pii> pip;
typedef pair<pii, pii> ppp;
typedef complex<ld> point;
typedef vector<point> polygon;
typedef vector<ll> vi;
typedef pair<point, int> ppi;
#define prec(n) \
cout.precision(n); \
cout << fixed
const ll mod = (1e9 + 7);
const ld eps = (1e-9);
const ll oo = (ll)(1e18 + 5);
#define pi acos(-1)
#define MAXN (ll)(1e6 + 5)
#define pb push_back
#define fs first
#define sc second
int n, m;
void problem(){
cin >> n >> m;
vector<int> a(n);
map<int,int> M;
for (int i = 0; i < n; i++){
cin >> a[i];
M[a[i]]++;
}
vector<int> b(m);
for (int i = 0; i < m; i++)
cin >> b[i];
sort(allr(a));
sort(allr(b));
int sum=0;
for(int i=0;i<m;i++){
if(b[i]<a[i]){
cout<<-1<<'\n';
return;
}
sum+=b[i]-a[i];
}
int d=a[m-1];
if(sum>n-m){
cout<<"-1\n";
return;
}
int extra=n-m-sum;
vi Ops;
int tot=n;
while(tot-m-sum){
int val=M.begin()->fs;
Ops.pb(val);
M[val+1]++;
M[val]--;
int rem=M[val];
if(rem==tot-m){
sum--;
}
if(sum<0){
cout<<-1<<'\n';
return;
}
if((M.begin()->sc)==0){
M.erase(M.begin());
}
val=M.begin()->fs;
M[val]--;
if((M.begin()->sc)==0){
M.erase(M.begin());
}
tot--;
if(M.size()==0){
cout<<-1<<'\n';
return;
}
}
a.resize(0);
for(auto p:M){
for(int j=0;j<p.sc;j++){
a.pb(p.fs);
}
}
reverse(all(a));
for(int i=0;i<m;i++){
if(a[i]>b[i]){
cout<<-1<<'\n';
return;
}
for(int j=a[i];j<b[i];j++)Ops.pb(j);
}
cout<<Ops.size()<<'\n';
for(auto a:Ops){
cout<<a<<' ';
}
cout<<'\n';
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
problem();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
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 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: 0ms
memory: 3616kb
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: 3804kb
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:
-1 1 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 -1 -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 -1 -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 -1 -1 -1 -...
result:
wrong answer Wrong answer, number of operation is not correct (test case 2)