Submission #252218

#TimeUsernameProblemLanguageResultExecution timeMemory
252218IgorIWatching (JOI13_watching)C++17
100 / 100
254 ms4376 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vector<int> > vvi; typedef vector<ll> vll; #define forn(i, n) for (int (i) = 0; (i) != (n); (i)++) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define popcount(x) __builtin_popcount(x) #define popcountll(x) __builtin_popcountll(x) #define fi first #define se second #define re return #define pb push_back #define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin()) #ifdef LOCAL #define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl #define ln cerr << __LINE__ << endl #else #define dbg(x) void(0) #define ln void(0) #endif // LOCAL int cx[4] = {-1, 0, 1, 0}; int cy[4] = {0, -1, 0, 1}; string Yes[2] = {"No", "Yes"}; string YES[2] = {"NO", "YES"}; const int N = 3400; int n, p, q; int a[N]; int small[N], big[N]; int can(int M) { int j = 0; for (int i = 0; i < n; i++) { while (j < n && a[j] - a[i] + 1 <= M) j++; small[i] = j; } small[n] = n; j = 0; for (int i = 0; i < n; i++) { while (j < n && a[j] - a[i] + 1 <= 2 * M) j++; big[i] = j; } big[n] = n; vector<vector<int> > dp(p + 1, vector<int>(q + 1)); for (int s = 0; s <= p; s++) { for (int b = 0; b <= q; b++) { if (s < p) { dp[s + 1][b] = max(dp[s + 1][b], small[dp[s][b]]); } if (b < q) { dp[s][b + 1] = max(dp[s][b + 1], big[dp[s][b]]); } } } return (dp[p][q] == n); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> p >> q; for (int i = 0; i < n; i++) { cin >> a[i]; } if (p + q >= n) { cout << 1; return 0; } sort(a, a + n); int L = 0, R = 1e9 + 7; while (L + 1 < R) { int M = (L + R) / 2; if (can(M)) R = M; else L = M; } cout << R << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...