답안 #1101624

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1101624 2024-10-16T11:57:13 Z stdfloat 구경하기 (JOI13_watching) C++17
0 / 100
1000 ms 19524 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define ff	first
#define ss	second
#define pii	pair<int, int>

#define sz(v)	(int)(v).size()
#define all(v)	(v).begin(), (v).end()

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);

	int n, p, q;
	cin >> n >> p >> q;

	p = min(n, p); q = min(n, q);

	vector<int> a(n + 1, INT_MIN);
	for (int i = 1; i <= n; i++)
		cin >> a[i];

	sort(1 + all(a));

	int l = 0, r = (int)1e9;
	while (l <= r) {
		int md = (l + r) >> 1;

		int x = 0, y = 0;
		vector<pii> dp[n + 1]; dp[0] = {{0, 0}};
		for (int i = 1; i <= n; i++) {
			while (x < n && a[x + 1] <= a[i] - md) x++;
			while (y < n && a[y + 1] <= a[i] - (md << 1)) y++;

			vector<pii> v;
			for (auto j : dp[x])
				if (j.ff < p) v.push_back({j.ff + 1, j.ss});
			for (auto j : dp[y])
				if (j.ss < q) v.push_back({j.ff, j.ss + 1});

			sort(v.begin(), v.end());
			for (int j = 0; j < sz(v); j++)
				if (!j || dp[i].back().ss > v[j].ss) dp[i].push_back(v[j]);
		
			assert(sz(dp[i]) <= n);
		}

		if (dp[n].empty()) l = md + 1;
		else r = md - 1;
	}

	cout << l;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Runtime error 1 ms 592 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Execution timed out 1079 ms 19524 KB Time limit exceeded
4 Halted 0 ms 0 KB -