QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#536446#4571. Even SplitLavineRE 0ms3952kbC++231.7kb2024-08-29 12:57:072024-08-29 12:57:08

Judging History

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

  • [2024-08-29 12:57:08]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3952kb
  • [2024-08-29 12:57:07]
  • 提交

answer

#include <cstdio>
#include <algorithm>
#include <utility>
#include <bits/stdc++.h>
using namespace std ;
using namespace std;
typedef pair<int, int> pii;
constexpr int MAXN = 100'005;

int v[MAXN];
pii segs[MAXN];
int ans[MAXN];

int main()
{
	int len, n;
	scanf("%d %d", &len, &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &v[i]);
	v[n] = len;

	int minlen;
	{
		const auto is_min_ok = [len, n](int cmin) -> bool
		{
			int start = 0;
			for (int i = 0; i < n; i++)
			{
				if (start > v[i])
					return false;
				start = max(start + cmin, v[i]);
			}
			return start <= len;
		};

		int left = 1, right = len + 1;
		while (left + 1 != right)
		{
			int m = (left + right) / 2;
			if (is_min_ok(m))
				left = m;
			else
				right = m;
		}
		minlen = left;
	}

	int maxlen;
	{
		const auto is_max_ok = [len, n](int cmax) -> bool
		{
			int start = 0;
			for (int i = 0; i < n; i++)
			{
				if (start + cmax < v[i])
					return false;
				start = min(start + cmax, v[i + 1]);
			}
			return start == len;
		};

		int left = 0, right = len;
		while (left + 1 != right)
		{
			int m = (left + right) / 2;
			if (is_max_ok(m))
				right = m;
			else
				left = m;
		}
		maxlen = right;
	}

	segs[0] = {0, 0};
	for (int i = 0; i < n; i++)
	{
		auto &[start, end] = segs[i];
		start = max(start, v[i] - maxlen);
		end = min(end, v[i]);
		segs[i + 1] = {max(start + minlen, v[i]), end + maxlen};
	}
    assert(segs[n].second==len);
	ans[n] = len;
	for (int i = n - 1; i >= 0; i--)
		ans[i] = max(segs[i].first, ans[i + 1] - maxlen);

	for (int i = 0; i < n; i++)
		printf("%d %d\n", ans[i], ans[i + 1]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3920kb

input:

6 3
1 3 5

output:

0 2
2 4
4 6

result:

ok Minimal imbalance is 0

Test #2:

score: 0
Accepted
time: 0ms
memory: 3820kb

input:

10 2
1 2

output:

0 2
2 10

result:

ok Minimal imbalance is 6

Test #3:

score: 0
Accepted
time: 0ms
memory: 3952kb

input:

100 10
14 26 29 31 34 42 44 48 49 68

output:

0 14
14 26
26 29
29 32
32 35
35 42
42 45
45 48
48 68
68 100

result:

ok Minimal imbalance is 29

Test #4:

score: -100
Runtime Error

input:

100 10
3 42 45 58 69 73 75 78 84 88

output:


result: