Submission #1139958

#TimeUsernameProblemLanguageResultExecution timeMemory
1139958jackofall718구경하기 (JOI13_watching)C++20
0 / 100
0 ms324 KiB
#include <bits/stdc++.h> #include <chrono> #define ll long long int #define endl '\n' #define vn vector<ll> #define vi vector<pair <ll,ll>> using namespace std; using namespace std::chrono; const int MAX_N = 1e9 + 7; #define pii pair<ll,ll> const ll INF = 0x3f3f3f3f3f3f3f3f; #define pb push_back #define srt(vp) sort(vp.begin(), vp.end()) int main() { ios::sync_with_stdio(false); cin.tie(nullptr); auto start = high_resolution_clock::now(); ll n,p,q; cin >> n >> p >> q; p = min(p,n); q = min(q,n); vn v(n); for (auto &x : v) cin >> x; sort(v.begin(), v.end()); ll lo = 1; ll ho = v[n-1]-v[0]; while (lo <= ho){ ll mid = (lo + ho) / 2; vector<vector<ll>> dp(p+1, vector<ll>(q+1, -1)); dp[0][0]=-1;//not 0 because we have to cover event 0 also bool check = false; for (ll i = 0; i <= p; i++){ for (ll j = 0; j <= q; j++){ ll x = i > 0 ? dp[i-1][j] : -1; ll y = j > 0 ? dp[i][j-1] : -1; if (x < n-1 && i > 0){ ll newdist = upper_bound(v.begin(), v.end(), v[x+1] + mid) - v.begin() - 1;//i forgot to substract v.begin() so the dp values are the max index they take dp[i][j] = max(dp[i][j], newdist); } if (y < n-1 && j > 0){ ll newdist1 = upper_bound(v.begin(), v.end(), v[y+1] + 2 * mid) - v.begin() - 1; //x+1 and y+1 cuz we putting shield on the next section dp[i][j] = max(dp[i][j], newdist1); } //basically just dp to decide the optimal placement of small and large shields if (dp[i][j] >= n-1){ check = true; } } } if (check) ho = mid-1; else lo = mid + 1; //mid +1 not mid } cout<<lo<< endl; auto stop = high_resolution_clock::now(); auto duration = duration_cast<microseconds>(stop - start); //cout << "Time taken by function: " << duration.count() << " microseconds" << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...