Submission #30510

#TimeUsernameProblemLanguageResultExecution timeMemory
30510zoomswkAliens (IOI16_aliens)C++14
41 / 100
696 ms129752 KiB
#include "aliens.h" #include <bits/stdc++.h> using namespace std; vector<pair<int, int>> p; int L[100005], R[100005]; long long dp[4005][4005]; void run(int l, int r, int opt_l, int opt_r, int lv){ if(l > r) return; int mid = (l+r)>>1; int new_opt = -1; for(int x=opt_l; x<=min(opt_r, mid); x++){ long long cst = dp[x-1][lv-1]+1LL*(R[mid]-L[x]+1)*(R[mid]-L[x]+1)-(R[x-1]-L[x]+1 > 0 ? 1LL*(R[x-1]-L[x]+1)*(R[x-1]-L[x]+1): 0LL); if(cst < dp[mid][lv]){ dp[mid][lv] = cst; new_opt = x; } } run(l, mid-1, opt_l, new_opt, lv); run(mid+1, r, new_opt, opt_r, lv); return; } long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c){ for(int i=0; i<n; i++) p.push_back({min(r[i], c[i]), -max(r[i], c[i])}); sort(p.begin(), p.end()); int N=1, tmp_mx=-1; for(int i=0; i<n; i++){ if(-p[i].second > tmp_mx){ L[N] = p[i].first, R[N] = -p[i].second; tmp_mx = -p[i].second; N++; } } N--; R[0] = -1e9; for(int i=1; i<=N; i++) for(int j=0; j<=k; j++) dp[i][j] = 1e18; for(int i=1; i<=N; i++) dp[i][1] = 1LL*(R[i]-L[1]+1)*(R[i]-L[1]+1); for(int i=2; i<=min(N, k); i++) run(1, N, 1, N, i); return dp[N][min(N, k)]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...