답안 #976123

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
976123 2024-05-06T07:55:36 Z vjudge1 구경하기 (JOI13_watching) C++17
100 / 100
371 ms 30556 KB
/*

*/

#include<bits/stdc++.h>
using namespace std;

#define int long long

const int inf = 2e9;

int n, p, q, k;
vector<int> a, nxt1, nxt2;
vector<vector<int>> dp;

int f(int i, int b) {
	if (i == n) {
		return 0;
	}
	if (dp[i][b] != -1) {
		return dp[i][b];
	}
	int ret = f(nxt1[i], b) + 1;
	if (b > 0) ret = min(ret, f(nxt2[i], b - 1));
	return dp[i][b] = ret;
}

signed main() {
	cin >> n >> p >> q;

	a.resize(n);
	nxt1.resize(n);
	nxt2.resize(n);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	sort(a.begin(), a.end());

	if (p + q >= n) {
		cout << 1 << '\n';
		return 0;
	}

	int lo = 1, hi = 1e9, ans = 1e9;
	while (lo <= hi) {
		k = (lo + hi) >> 1;

		for (int i = 0; i < n; i++) {
			bool ok = 0;
			for (int j = i + 1; j < n; j++) {
				if (a[j] + 1 > a[i] + k) {
					nxt1[i] = j, ok = 1;
					break;
				} 
			}
			if (!ok) {
				nxt1[i] = n;
			}
			ok = 0;
			for (int j = i + 1; j < n; j++) {
				if (a[j] + 1 > a[i] + 2 * k) {
					nxt2[i] = j, ok = 1;
					break;
				} 
			}
			if (!ok) {
				nxt2[i] = n;
			}
		}

		dp.assign(n, vector<int>(q + 1, -1));

		if (f(0, q) <= p) {
			hi = k - 1, ans = k;
		} else {
			lo = k + 1;
		}
	}

	cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 600 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 11 ms 604 KB Output is correct
8 Correct 127 ms 12380 KB Output is correct
9 Correct 28 ms 2392 KB Output is correct
10 Correct 27 ms 1976 KB Output is correct
11 Correct 371 ms 30556 KB Output is correct
12 Correct 213 ms 15968 KB Output is correct
13 Correct 15 ms 604 KB Output is correct
14 Correct 11 ms 772 KB Output is correct
15 Correct 9 ms 600 KB Output is correct