Submission #981246

# Submission time Handle Problem Language Result Execution time Memory
981246 2024-05-13T03:03:23 Z Amaarsaa Watching (JOI13_watching) C++14
50 / 100
11 ms 2652 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long ;
ll a[2004];
ll n;
bool Can(ll x, ll s, ll small, ll large) {
	bool dp[102][102][102] = {0};
	int i, j,r;
	dp[n][small][large]= 1;
	for (i = n; i >= 1; i --) {
		for (j = 0; j <= small; j ++) {
			for ( r = 0; r <= large; r ++) {
				if ( r > 0 && dp[i][j][r]) {
					s = lower_bound(a + 1, a + n + 1, a[i] - (2 * x) + 1) - a;
					s --;
					if (s == 0) return true;
					dp[s][j][r - 1] = 1;
				}
				if ( j > 0 && dp[i][j][r]) {
					s = lower_bound(a + 1, a + n + 1, a[i] - x + 1) - a;
					s --;
					if (s == 0) return true;
					dp[s][j - 1][r] = 1;
				}
				
			}
		}
	}
	return 0;
}

int main() {
//	freopen("moocast.in", "r", stdin);
//	freopen("moocast.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll i, lo, hi, mid, small, large, j;
	
	cin >> n >> small >> large;
	if ( small + large >= n) {
		cout << 1 << endl;
		return 0;
	}
	for (i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	sort ( a + 1, a + n + 1);
	lo = 1;
	hi = 1e9;
	
	while ( lo < hi) {
		mid = (lo + hi)/2;
		if ( !Can(mid, n, small, large)) lo = mid + 1;
		else hi = mid;
	}
	cout << lo  << endl;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:38:35: warning: unused variable 'j' [-Wunused-variable]
   38 |  ll i, lo, hi, mid, small, large, j;
      |                                   ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1372 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 1372 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 2 ms 1372 KB Output is correct
8 Correct 3 ms 1536 KB Output is correct
9 Correct 2 ms 1372 KB Output is correct
10 Correct 6 ms 1488 KB Output is correct
11 Correct 7 ms 1372 KB Output is correct
12 Correct 11 ms 1500 KB Output is correct
13 Correct 2 ms 1372 KB Output is correct
14 Correct 2 ms 1372 KB Output is correct
15 Correct 2 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 2652 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -