Submission #522454

#TimeUsernameProblemLanguageResultExecution timeMemory
522454hohohahaWatching (JOI13_watching)C++14
100 / 100
167 ms31784 KiB
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
// #pragma GCC optimize("unroll-loops")
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// #include <ext/rope>
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
#include "bits/stdc++.h"

using namespace std;

#define li long long
#define ld long double
#define ii pair<int, int>
#define vi vector<int> 
#define vvi vector<vi>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define eb emplace_back
#define em emplace
#define ob pop_back
#define om pop
#define of pop_front

#define fori(i, a, b) for(int i = (int) (a); i <= (int) (b); ++i)
#define ford(i, a, b) for(int i = (int) (a); i >= (int) (b); --i)
#define forIT(it, begin, end) for(__typeof(end) it = (begin) + ((begin) > (end)); it != (end) - ((begin) > (end)); it += 1 - 2 * ((begin) > (end)))
#define b_e(x) begin(x), end(x)
#define sz(x) ((int)(x).size())
#define bitc __builtin_popcountll

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand rng
#define endl '\n'
#define sp ' '

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

void solve();

signed main() {
// freopen("test.inp","r",stdin);
// freopen("test.out","w",stdout);
   fastio;
   int tc = 1;
   fori(test, 1, tc) {
      solve();
   }
   return 0;
}

#define int long long
const ld pi = 4 * atan(1.0), eps = 1e-9;
const int maxn = 2005; 
int n, p, q; 
int arr[maxn]; 
int to[maxn]; 
int t2[maxn];
int dp[maxn][maxn]; 
bool ok(int w) { 
	int pt = n; 
	ford(i, n, 1) { 
		while(arr[pt] - arr[i] >= w) --pt; 
		to[i] = pt;
	}
	pt = n; 
	ford(i, n, 1) { 
		while(arr[pt] -  arr[i] >= 2 * w) --pt; 
		t2[i] = pt; 
	}
	fori(i, 0, n) fori(j, 0, n) dp[i][j] = 0; 
	fori(i, 0, p) fori(j, 0, q) { 
		int idx = dp[i][j]; 
		if(idx == n) return 1; 
		dp[i + 1][j] = max(dp[i + 1][j], to[dp[i][j] + 1]); 
		dp[i][j + 1] = max(dp[i][j + 1], t2[dp[i][j] + 1]); 
	}
	return 0; 
}
void solve() {
	cin >> n >> p >> q; p = min(p, n); q = min(q, n); 
	fori(i, 1, n) cin >> arr[i]; 
	sort(arr + 1, arr + n + 1); 
	int lo = 1, hi = 1e9; 
	while(lo < hi) { 
		int mi = lo + hi >> 1; 
		if(ok(mi)) hi = mi; 
		else lo = mi + 1; 
	}
	cout << lo; 
}

Compilation message (stderr)

watching.cpp: In function 'void solve()':
watching.cpp:91:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   91 |   int mi = lo + hi >> 1;
      |            ~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...