Submission #30512

#TimeUsernameProblemLanguageResultExecution timeMemory
30512zoomswkAliens (IOI16_aliens)C++14
60 / 100
2000 ms7556 KiB
#include "aliens.h" #include <bits/stdc++.h> using namespace std; vector<pair<int, int>> p; int L[100005], R[100005]; long long dp[100005][2]; 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; int now = lv&1, prev = !now; for(int x=opt_l; x<=min(opt_r, mid); x++){ long long cst = dp[x-1][prev]+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][now]){ dp[mid][now] = 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++) dp[i][0] = 1e18; for(int i=1; i<=min(N, k); i++){ int now = i&1; for(int j=1; j<=N; j++) dp[j][now] = 1e18; run(1, N, 1, N, i); } return dp[N][min(N, k)&1]; }
#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...