답안 #34573

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
34573 2017-11-13T05:30:30 Z sinhriv 구경하기 (JOI13_watching) C++14
0 / 100
63 ms 20964 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 2202;
 
int n, p, q;
int a[N];
int f[N][N];
 
int main(){
	if(fopen("1.inp", "r")){
		freopen("1.inp", "r", stdin);
	}
 
	scanf("%d%d%d", &n, &p, &q);
 
	for(int i = 1; i <= n; ++i){
		scanf("%d", a + i);
	}
 
	p = min(p, n);
	q = min(q, n);
 
	sort(a + 1, a + n + 1);
 
	int low = 1, high = 1e9, ans = 1e9;
 
	while(low <= high){
		int w = (low + high) >> 1;
	
		memset(f, 60, sizeof f);
		f[0][0] = 0;
 
		bool ok = false, debug = false;
 
			
		for(int j = 0; j <= p; ++j){
 
			int pterOne = 0, pterTwo = 0;

			for(int i = 1; i <= n; ++i){

				while(a[i] - a[pterOne + 1] + 1 > w) ++pterOne;
				while(a[i] - a[pterTwo + 1] + 1 > w + w + 1) ++pterTwo;
				
				if(j > 0 && pterOne < i) f[i][j] = min(f[i][j], f[pterOne][j - 1]);
				if(pterTwo < i) f[i][j] = min(f[i][j], f[pterTwo][j] + 1);
				
 
				if(i == n && f[i][j] <= q){
					ok = true;
				}
			}
		}
 
 
		if(ok == false){
			low = w + 1;
		}
		else{
			ans = w;
			high = w - 1;
		}
	}
 
	cout << ans;
 
	return 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:35:20: warning: unused variable 'debug' [-Wunused-variable]
   bool ok = false, debug = false;
                    ^
watching.cpp:13:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen("1.inp", "r", stdin);
                               ^
watching.cpp:16:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &n, &p, &q);
                             ^
watching.cpp:19:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", a + i);
                     ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 20964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 53 ms 20964 KB Output isn't correct
2 Halted 0 ms 0 KB -