QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#135885#6400. Game: CelestekyEEccccccWA 325ms19084kbC++142.6kb2023-08-06 14:35:362023-08-06 14:35:38

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-06 14:35:38]
  • 评测
  • 测评结果:WA
  • 用时:325ms
  • 内存:19084kb
  • [2023-08-06 14:35:36]
  • 提交

answer

// Author: kyEEcccccc

#include <bits/stdc++.h>

using namespace std;

using LL = long long;
using ULL = unsigned long long;

#define F(i, l, r) for (int i = (l); i <= (r); ++i)
#define FF(i, r, l) for (int i = (r); i >= (l); --i)
#define MAX(a, b) ((a) = max(a, b))
#define MIN(a, b) ((a) = min(a, b))
#define SZ(a) ((int)((a).size()) - 1)

constexpr int N = 1000005;

int n;
LL a[N], dl, dr;
int b[N];

namespace Case1
{
	LL f[N], baka[N];

	void solve(void)
	{
		f[n] = 1;
		int cl = n, cr = n, cp = n + 1;
		LL mx_l = LLONG_MIN / 2;
		FF(i, n - 1, 1)
		{
			while (a[cl] - a[i] >= dl)
			{
				MAX(mx_l, f[cl]);
				--cl;
			}
			while (a[cr] - a[i] > dr) --cr;
			if (cr < cp)
			{
				mx_l = LLONG_MIN / 2;
				cp = cl + 1;
				baka[cl] = LLONG_MIN / 2;
				F(i, cl + 1, cr) baka[i] = max(baka[i - 1], f[i]);
			}
			f[i] = max(mx_l, baka[cr]) + 1;
		}
		if (f[1] < 0) cout << "-1\n";
		else
		{
			cout << f[1] << '\n';
			F(i, 1, f[1]) cout << 1 << ' ';
			cout << '\n';
		}
	}
}

namespace Case2
{
	bitset<10048> to[10048], baka[10048], tmp;
	int ord[10048];

	void solve(void)
	{
		to[n].reset();
		to[n].set(n);
		int cl = n, cr = n, cp = n + 1;
		tmp.reset();
		FF(i, n - 1, 1)
		{
			while (a[cr] - a[i] > dr) --cr;
			while (a[cl] - a[i] >= dl)
			{
				if (cr >= cp) tmp |= to[cl];
				--cl;
			}
			if (cr < cp)
			{
				tmp.reset();
				cp = cl + 1;
				baka[cl].reset();
				F(i, cl + 1, cr) baka[i] = baka[i - 1] | to[i];
			}
			to[i] = tmp | baka[cr];
			to[i].set(i);
		}

		if (!to[1].test(n)) return cout << "-1\n", void();

		iota(ord + 1, ord + n + 1, 1);
		sort(ord + 1, ord + n + 1, [] (int x, int y)
			{ return b[x] > b[y]; });
		set<LL> pos; multiset<int> val;
		pos.insert(1), val.insert(-b[1]);
		pos.insert(n), val.insert(-b[n]);
		F(_, 1, n)
		{
			int i = ord[_];
			if (i == 1 || i == n) continue;
			int prv = *prev(pos.lower_bound(i)), nxt = *pos.upper_bound(i);
			if (to[prv].test(i) && to[i].test(nxt))
			{
				pos.insert(i);
				val.insert(-b[i]);
			}
		}
		cout << val.size() << '\n';
		for (auto x : val) cout << -x << ' ';
		cout << '\n';
	}
}

void work(void)
{
	cin >> n >> dl >> dr;
	F(i, 1, n) cin >> a[i];
	a[n + 1] = 10000000000LL;
	bool all_1 = true;
	F(i, 1, n)
	{
		cin >> b[i];
		if (b[i] != 1) all_1 = false;
	}
	if (all_1) Case1::solve();
	else Case2::solve();
}

signed main(void)
{
	// freopen("jump.in", "r", stdin);
	// freopen("jump.out", "w", stdout);
	ios::sync_with_stdio(0), cin.tie(nullptr);

	int _; cin >> _;
	while (_--) work();
	
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 9696kb

input:

2
5 2 3
1 2 3 4 5
5 2 3 1 4
3 1 2
1 4 7
3 3 3

output:

3
5 4 3 
-1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 325ms
memory: 19084kb

input:

10000
57 8 11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
11 16 7 7 10 13 9 14 10 1 12 4 8 13 3 20 16 7 16 19 20 8 19 7 16 6 17 13 7 19 17 11 12 17 6 3 7 8 14 2 4 15 5 18 16 7 20 9 1...

output:

7
20 20 19 14 12 11 3 
-1
6
6 5 3 2 1 1 
-1
185
20 20 20 20 20 20 20 20 19 19 19 19 19 19 19 19 19 19 19 19 18 18 18 18 18 17 17 17 17 17 17 17 17 16 16 16 16 16 16 16 16 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 14 14 14 14 14 14 14 13 13 13 13 13 13 13 13 13 12 12 12 12 12 12 12 ...

result:

wrong answer 10th lines differ - expected: '20 20 20 20 19 19 19 19 18 18 17 17 16 16 13 6 6 3', found: '20 20 20 20 19 19 19 18 18 17 17 16 13 12 6 6 5 3 '