답안 #485345

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
485345 2021-11-07T07:46:21 Z zhougz 구경하기 (JOI13_watching) C++17
50 / 100
1000 ms 169356 KB
/**
 *    author: chowgz
 *    created: 06/11/2021 20:19:08
**/
#include <bits/stdc++.h>

using namespace std;

int n, p, q;
const int MAXN = 2'000;
int arr[MAXN + 5];
int m;
unordered_map<long long, bool> mmap;
int nxt1[MAXN + 5], nxt2[MAXN + 5];

long long hsh(int x, int y, int z) {
	return x * 3'000 * 3'000 + y * 3'000 + z;
}

bool dp(int x, int y, int z) {
	// x: considering arr[x], y: # short pieces left, z: # long pieces left
#ifdef LOCAL
	cerr << "x: " << x << " y: " << y << " z: " << z << endl;
#endif
	if (y < 0 || z < 0) {
		return false;
	}
	if (y + z >= n - x) {
		return true;
	}
	if (mmap.find(hsh(x, y, z)) != mmap.end()) {
		return mmap[hsh(x, y, z)];
	}
	return mmap[hsh(x, y, z)]
		= dp(nxt2[x], y, z - 1) || dp(nxt1[x], y - 1, z);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> p >> q;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	if (p + q >= n) {
		cout << 1 << '\n';
		return 0;
	}
	sort(arr, arr + n);
	int l = 1, r = 1'000'000'000;
	while (l != r) {
		m = (l + r) / 2;
		mmap.clear();
		for (int i = 0; i < n; i++) {
			nxt1[i] = upper_bound(arr, arr + n, arr[i] + m - 1) - arr;
			nxt2[i] = upper_bound(arr, arr + n, arr[i] + 2 * m - 1) - arr;
		}
		if (dp(0, p, q)) {
			r = m;
		} else {
			l = m + 1;
		}
	}
	cout << l << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 216 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 5 ms 488 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 5 ms 460 KB Output is correct
8 Execution timed out 1085 ms 169356 KB Time limit exceeded
9 Halted 0 ms 0 KB -