Submission #1139954

#TimeUsernameProblemLanguageResultExecution timeMemory
1139954jackofall718구경하기 (JOI13_watching)C++20
0 / 100
0 ms328 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; 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; ll dp[p+1][q+1] = {}; // be sure to make it empty 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] + 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] + 2 * mid) - v.begin() - 1; 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; 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; // Un-commented for utility return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...