답안 #553637

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
553637 2022-04-26T12:46:01 Z QwertyPi 구경하기 (JOI13_watching) C++14
0 / 100
376 ms 31748 KB
#include <bits/stdc++.h>
#define N 2001
using namespace std;

int dp[N][N];
int w1[N], w2[N];
int n, p, q;
vector<int> a;

bool ok(int w){
	for(int i = 0; i <= n; i++) for(int j = 0; j <= n; j++) dp[i][j] = (1 << 30); dp[0][0] = 0;
	for(int j = 0; j <= q; j++){
		int w1 = 0, w2 = 0;
		for(int i = j + 1; i <= n; i++){
			while(w1 < n && a[w1] <= a[i - 1] - w) w1++;
			while(w2 < n && a[w2] <= a[i - 1] - w * 2) w2++;
			if(j > 0) dp[i][j] = min(dp[i][j], dp[w2][j - 1]);
			dp[i][j] = min(dp[i][j], dp[w1][j] + 1);
		}
		for(int i = 1; i <= n; i++) dp[i][j + 1] = min(dp[i][j], dp[i][j + 1]);
	}
	bool ret = false;
	for(int j = 0; j <= q; j++) ret |= dp[n][j] <= p - j;
	return ret;
}

int main(){
	cin >> n >> p >> q;
	p += q;
	p = min(n, p); q = min(n / 2, q);
	for(int i = 0; i < n; i++){
		int v; cin >> v;
		a.push_back(v);
	}
	sort(a.begin(), a.end());
	vector<int> d;
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){
			d.push_back(a[j] - a[i]);
			d.push_back((a[j] - a[i]) / 2 + 1);
		}
	}
	sort(d.begin(), d.end());
	d.resize(unique(d.begin(), d.end()) - d.begin());
	int l, r;
	for(l = 0, r = d.size(); l != r;){
		int m = (l + r) / 2;
		if(ok(d[m])){
			r = m;
		}else{
			l = m + 1;
		}
	}
	cout << d[l] << endl;
}

Compilation message

watching.cpp: In function 'bool ok(int)':
watching.cpp:11:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   11 |  for(int i = 0; i <= n; i++) for(int j = 0; j <= n; j++) dp[i][j] = (1 << 30); dp[0][0] = 0;
      |  ^~~
watching.cpp:11:80: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   11 |  for(int i = 0; i <= n; i++) for(int j = 0; j <= n; j++) dp[i][j] = (1 << 30); dp[0][0] = 0;
      |                                                                                ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 852 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 376 ms 31748 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -