답안 #952186

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952186 2024-03-23T09:15:40 Z SmuggingSpun 구경하기 (JOI13_watching) C++14
100 / 100
231 ms 15560 KB
#include<bits/stdc++.h>
#define taskname "watching"
using namespace std;
const int INF = 1e9;
const int lim = 2e3 + 5;
int a[lim];
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen(taskname".inp", "r")){
		freopen(taskname".inp", "r", stdin);
	}
	int n, p, q, ans, low = 1, high = 1e9;
	cin >> n >> p >> q;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	if(p + q >= n){
		return cout << 1, 0;
	}
	sort(a + 1, a + n + 1);
	while(low <= high){
		int mid = (low + high) >> 1;
		vector<vector<int>>dp(n + 1, vector<int>(q + 1, INF));
		for(int i = 0; i <= q; i++){
			dp[0][i] = 0;
		}
		for(int i = 1, lp = 1, lq = 1; i <= n; i++){
			while(a[i] - a[lp] >= mid){
				lp++;
			}
			while(a[i] - a[lq] >= (mid << 1)){
				lq++;
			}
			dp[i][0] = dp[lp - 1][0] + 1;
			for(int j = 1; j <= q; j++){
				dp[i][j] = min(dp[lq - 1][j - 1], dp[lp - 1][j] + 1);
			}
		}
		if(dp[n][q] <= p){
			high = (ans = mid) - 1;
		}
		else{
			low = mid + 1;
		}
	}
	cout << ans;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:10:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |   freopen(taskname".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:46:10: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |  cout << ans;
      |          ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 388 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 452 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 356 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 87 ms 6620 KB Output is correct
9 Correct 16 ms 1576 KB Output is correct
10 Correct 12 ms 1236 KB Output is correct
11 Correct 231 ms 15560 KB Output is correct
12 Correct 110 ms 8320 KB Output is correct
13 Correct 4 ms 604 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 604 KB Output is correct