# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
956339 | 2024-04-01T16:16:25 Z | steveonalex | Watching (JOI13_watching) | C++17 | 2 ms | 348 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define MASK(i) (1LL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) #define ALL(v) (v).begin(), (v).end() ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll LASTBIT(ll mask){return (mask) & (-mask);} int pop_cnt(ll mask){return __builtin_popcountll(mask);} int ctz(ll mask){return __builtin_ctzll(mask);} int logOf(ll mask){return __lg(mask);} mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);} template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b) {a = b; return true;} return false; } template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b) {a = b; return true;} return false; } template <class T> void printArr(T& container, char separator = ' ', char finish = '\n'){ for(auto item: container) cout << item << separator; cout << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } const long N = 2007; long n, a, b; vector<long> x; long dp[N][N]; bool check(long w){ vector<long> nxt1(n+1), nxt2(n+1); for(long i = 0; i<n; ++i){ if (x[i] + w > 1e9){ nxt1[i] = nxt2[i] = n; } else{ nxt1[i] = lower_bound(ALL(x), x[i] + w) - x.begin(); nxt2[i] = lower_bound(ALL(x), x[i] + w*2) - x.begin(); } } nxt1[n] = nxt2[n] = n; for(long i = 0; i<=a; ++i) for(long j = 0; j<=b; ++j) dp[i][j] = 0; for(long i = a; i>=0; --i) for(long j = b; j>=0; --j){ if (i > 0) maximize(dp[i-1][j], nxt1[dp[i][j]]); if (j > 0) maximize(dp[i][j-1], nxt2[dp[i][j]]); } return (dp[0][0] >= n); } int main(void){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); freopen("paint.inp", "r", stdin); freopen("paint.out", "w", stdout); cin >> n >> a >> b; x.resize(n); for(long i = 0; i<n; ++i) cin >> x[i]; sort(ALL(x)); if (a + b >= n){ cout << 1 << "\n"; return 0; } long l = 1, r = 1e9; long s = a + b; r = (r + s - 1) / s; while(l < r){ long mid = (l + r) >> 1; if (check(mid)) r = mid; else l = mid + 1; } cout << l << "\n"; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |