Submission #727740

#TimeUsernameProblemLanguageResultExecution timeMemory
727740sandry24Watching (JOI13_watching)C++17
0 / 100
2 ms340 KiB
#include <bits/stdc++.h> using namespace std; //#pragma GCC optimize("O3,unroll-loops") //#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pi; #define pb push_back #define mp make_pair #define f first #define s second const int maxn = 2005; vi events; int n, small, large; bool possible(int w){ vi small_range(n), large_range(n); int j = 0; for(int i = 0; i < n; i++){ while(j < n && events[j] - events[i] < w) j++; small_range[i+1] = j; j--; } j = 0; for(int i = 0; i < n; i++){ while(j < n && events[j] - events[i] < 2*w) j++; large_range[i+1] = j; j--; } vector<vi> dp(small+1, vi(large+1)); //dp[i][j] = highest index you can cover with i small j big for(int i = 0; i <= small; i++){ for(int j = 0; j <= large; j++){ if(i > 0) dp[i][j] = max(dp[i][j], small_range[dp[i-1][j] + 1]); if(j > 0) dp[i][j] = max(dp[i][j], large_range[dp[i][j-1] + 1]); } } return (dp[small][large] >= n); } void solve(){ cin >> n >> small >> large; if(small + large >= n){ cout << 1 << '\n'; return; } events = vi(n); for(int i = 0; i < n; i++){ cin >> events[i]; } sort(events.begin(), events.end()); int current = 0; for(int add = 1e9; add > 0; add /= 2){ while(!possible(current+add)) current += add; } cout << current+1 << '\n'; } int main(){ //freopen("input.txt", "r", stdin); //freopen("test.out", "w", stdout); //ios::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...