QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#753773 | #9574. Strips | rool123 | WA | 45ms | 3676kb | C++23 | 2.4kb | 2024-11-16 13:36:34 | 2024-11-16 13:36:35 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define vi vector<int>
#define vll vector<long long>
#define double long double
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<'*'<<x<<'\n';
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define rep(x, y) for(int i=(x); i<=(y); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int INF=0x3f3f3f3f;
const ll LINF=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
ll gcd(ll a,ll b)
{
return b?gcd(b,a%b):a;
}
ll lcm(ll a,ll b)
{
return a*b/gcd(a,b);
}
ll qmi(ll a,ll b)
{
ll ans=1;
while(b)
{
if(b&1)ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
void solve()
{
// debug("**********");
map<int, int>l, r;
map<int, bool>ok;
int n, m, k, w;
cin >> n >> m >> k >> w;
vi red;
red.pb(0);
rep(1, n)
{
int x; cin >> x;
red.pb(x);
}
sort(all(red));
rep(1, m)
{
int x; cin >> x;
int lo = 0, ri = n;
while(lo < ri)
{
int mid = (lo + ri + 1) >> 1;
if(red[mid] < x)lo = mid;
else ri = mid - 1;
}
if(!l[lo])l[lo] = x;
else l[lo] = min(l[lo], x);
if(!r[lo])r[lo] = x;
else r[lo] = max(r[lo], x);
ok[lo] = 1;
// debug(lo);
}
// rep(0, n-1)
// {
// if(ok[i])cout << i << ' ';
// }
int L = red[1], R = red[1], preR = 0;
int lidx = 1, ridx = 1;
vi res;
int i = 1;
while(i <= n)
{
if(ok[i-1] && ok[i] && l[i] - r[i-1] + 1 < k)
{
cout << -1 << endl;
return;
}
L = max(preR+1, red[i]), lidx = i, ridx = i;
while(1)
{
if(!ok[ridx] && ridx < n && red[ridx+1] - L + 1 <= k)ridx++;
else break;
}
// debug(ridx);
R = red[ridx];
// debug(L);
int len = R - L + 1;
int diff = k - len;
int L2 = L;
L = max({r[i-1]+1, L - diff, preR+1});
diff -= (L2 - L);
if(ok[ridx])R = min(l[ridx]-1, R+diff);
else R += diff;
// cout << "L=" << L << endl;
// cout << "R=" << R << endl;
// cout << "ridx=" << ridx << endl;
// cout << "lidx=" << lidx << endl;
res.pb(L);
if(R - L + 1 != k || R > w)
{
cout << -1 << endl;
return;
}
i = max(i, ridx) + 1;
preR = R;
}
cout << res.size() << endl;
for(int x:res)cout << x << ' ';
cout << endl;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int _;
_=1;
cin>>_;
while(_--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3504kb
input:
4 5 2 3 16 7 11 2 9 14 13 5 3 2 4 11 6 10 2 1 11 2 1 2 6 1 5 3 2 1 2 6 1 5 2
output:
4 1 7 10 14 -1 2 1 4 -1
result:
ok ok 4 cases (4 test cases)
Test #2:
score: -100
Wrong Answer
time: 45ms
memory: 3676kb
input:
11000 3 8 2 53 32 3 33 35 19 38 20 1 30 10 6 7 10 1 42 3 14 4 36 28 40 22 17 20 12 41 27 7 1 19 13 9 6 6 13 78 55 76 53 32 54 58 62 45 21 4 7 61 8 7 3 68 9 26 54 31 22 3 38 65 34 16 58 47 52 29 53 5 8 4 33 33 5 30 6 15 27 12 9 28 19 2 13 10 6 1 2 48 8 12 48 1 41 31 40 7 6 7 61 20 19 30 52 49 17 40 3...
output:
2 2 32 7 3 4 14 22 28 36 40 3 22 46 64 8 1 7 20 24 30 36 54 63 3 3 14 30 6 1 7 11 30 41 47 4 14 27 34 47 2 42 65 1 27 1 9 1 62 5 24 33 42 47 60 2 3 31 3 11 19 29 3 2 15 33 3 25 30 42 3 2 17 59 4 1 11 21 32 2 53 65 3 49 58 65 3 43 60 78 1 78 4 1 11 15 21 5 3 7 17 36 48 2 1 44 ...
result:
wrong answer Participant didn't find a solution but the jury found one. (test case 73)