제출 #63562

#제출 시각아이디문제언어결과실행 시간메모리
63562yu0524구경하기 (JOI13_watching)C++14
100 / 100
412 ms16588 KiB
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
using namespace std;
typedef long long ll;
int N, p, q, a, dp[2001][2001];
vector<ll> arr;

int func(ll w, ll maxx = 0, int cur = 0, int sw = p) {
	if (cur >= arr.size()) return 0;
	if (maxx > arr[cur]) return func(w, maxx, cur + 1, sw);
	if (arr.size() - cur <= sw) return 0;

	if (dp[cur][sw] != -1) return dp[cur][sw];

	dp[cur][sw] = func(w, arr[cur] + 2*w, cur+1, sw) + 1;
	if (sw) dp[cur][sw] = min(dp[cur][sw], func(w, arr[cur] + w, cur + 1, sw - 1));
	return dp[cur][sw];
}

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

	cin >> N;
	cin >> p >> q;

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

	for (int i = 0; i < N; ++i) {
		cin >> a;
		arr.push_back(a);
	}
	sort(arr.begin(), arr.end());
	arr.resize(distance(arr.begin(), unique(arr.begin(), arr.end())));
	
	ll x = 1, y = 1000000000, mid, res;

	while (x <= y) {
		memset(dp, -1, sizeof(dp));
		mid = (x + y) >> 1;
		
		if (func(mid) <= q) {
			y = mid - 1;
			res = mid;
		}
		else {
			x = mid + 1;
		}
	}

	cout << res;
}

컴파일 시 표준 에러 (stderr) 메시지

watching.cpp: In function 'int func(ll, ll, int, int)':
watching.cpp:12:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (cur >= arr.size()) return 0;
      ~~~~^~~~~~~~~~~~~
watching.cpp:14:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (arr.size() - cur <= sw) return 0;
      ~~~~~~~~~~~~~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...