QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#755316#9574. Stripsxjt05WA 1ms5912kbC++232.7kb2024-11-16 17:02:212024-11-16 17:02:22

Judging History

This is the latest submission verdict.

  • [2024-11-16 17:02:22]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 5912kb
  • [2024-11-16 17:02:21]
  • Submitted

answer

#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<stack>
#include<string>
#define ll                                     long long
#define lowbit(x) (x & -x)
#define endl "\n"//                           交互题记得删除
using namespace std;
mt19937 rnd(time(0));
const ll mod = 998244353;
ll ksm(ll x, ll y)
{
	ll ans = 1;
	while (y)
	{
		if (y & 1)
		{
			ans = ans % mod * (x % mod) % mod;
		}
		x = x % mod * (x % mod) % mod;
		y >>= 1;
	}
	return ans % mod % mod;
}
ll gcd(ll x, ll y)
{
	if (y == 0)
		return x;
	else
		return gcd(y, x % y);
}
void fio()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
ll a[450000];
ll b[450000];
vector<ll> ans;
ll d[450000];
int main()
{
	fio();
	ll t;
	cin >> t;
	while (t--)
	{
		ans.clear();
		ll n, m, k, w;
		cin >> n >> m >> k >> w;
		for (ll i = 1; i <= n; i++)
		{
			cin >> a[i];
		}
		for (ll i = 1; i <= m; i++)cin >> b[i];
		b[m + 1] = w + 1;
		b[0] = 0;
		sort(a + 1, a + 1 + n);
		sort(b + 1, b + 1 + m);
		ll cnt = 1;
		ll l, r;
		ll op = 0;
		for (ll i = 0; i <= m; i++)
		{
			l = cnt;
			r = cnt;
			if (b[i+1] < a[cnt])continue;
			if (cnt == n + 1)break;
			while (a[cnt] >= b[i] && a[cnt] <= b[i + 1])
			{
				r = cnt;
				cnt++;
			}
			ll an = b[i];
			ll gs = 0;
			ll pd = 0;
			ll wz;
			for (ll j = l; j <= r; j++)
			{
				if (j == l)
				{
					wz = max(a[j] - k + 1, b[i] + 1);
					gs++;
					d[gs] = wz;
				}
				else
				{
					if (a[j] > wz + k - 1)
					{
						wz = max(wz + k, a[j] - wz + 1);
						gs++;
						d[gs] = wz;
					}
				}
				if (j == r)
				{
					if (wz + k - 1 < b[i + 1])
					{
						pd = 1;
					}
				}
			}
			if (pd == 1)
			{
				for (ll j = 1; j <= gs; j++)ans.push_back(d[j]);
				continue;
			}
			else if (pd == 0)
			{
				gs = 0;
				ll wz;
				for (ll j = l; j <= r; j++)
				{
					if (j == r)
					{
						wz = min(b[i + 1] - 1, a[j] + k - 1);
						gs++;
						d[gs] = wz - k + 1;
					}
					else
					{
						if (a[j] < wz - k + 1)
						{
							wz = min(wz - k, a[j] + wz - 1);
							gs++;
							d[gs] = wz;
						}

					}
					if (j == l)
					{
						if (d[gs] - k + 1 <= b[i])
						{
							pd = 1;
						}
					}
				}
				if (pd == 1)
				{
					op = 1;
					break;
				}
				else
				{
					for (ll j = 1; j <= gs; j++)ans.push_back(d[j]);
				}
			}
		}
		if (op)
			cout << -1 << endl;
		else
		{
			cout << ans.size() << endl;
			for (auto j : ans)
				cout << j << " ";
			cout << endl;
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5912kb

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 6 9 14 
4
1148 1144 1140 7 
2
1 4 
-1

result:

wrong answer Integer parameter [name=c] equals to 4, violates the range [-1, 3] (test case 2)