Submission #94554

#TimeUsernameProblemLanguageResultExecution timeMemory
94554someone_aaAliens (IOI16_aliens)C++17
12 / 100
215 ms4472 KiB
#include <bits/stdc++.h> #include "aliens.h" #define ll long long #define pb push_back #define mp make_pair #define P pair<ll,ll> using namespace std; const int maxn = 4100; ll dp[maxn][maxn]; int n, m, k; long long take_photos(int N, int M, int K, std::vector<int> r, std::vector<int> c) { n = N; m = M; k = K; vector<P>points; vector<ll> pref_max, pref_min; pref_max.pb(-1); pref_min.pb(LLONG_MAX); for(int i=0;i<N;i++) { points.pb(mp(r[i], c[i])); } points.pb(mp(-1, -1)); sort(points.begin(), points.end()); ll minv = INT_MAX, maxv = INT_MIN; for(int i=1;i<=n;i++) { minv = min(minv, min(points[i].first, points[i].second)); maxv = max(maxv, max(points[i].first, points[i].second)); dp[1][i] = (maxv - minv + 1) * (maxv - minv + 1); pref_max.pb(max(pref_max.back(), maxv)); pref_min.pb(min(pref_min.back(), minv)); } for(int p=2;p<=k;p++) { for(int i=1;i<=n;i++) { dp[p][i] = LLONG_MAX; ll minv = INT_MAX, maxv = INT_MIN; for(int j=i;j>=1;j--) { minv = min(minv, min(points[j].first, points[j].second)); maxv = max(maxv, max(points[j].first, points[j].second)); ll intersection = 0LL; if(pref_max[j-1] >= maxv) { if(pref_min[j-1] < minv) intersection = (maxv-minv+1); else intersection = maxv - pref_min[j-1] + 1; } else if(pref_max[j-1] >= minv) { if(pref_min[j-1] < minv) intersection = pref_max[j-1] - minv + 1; else intersection = pref_max[j-1] - pref_min[j-1] + 1; } dp[p][i] = min(dp[p][i], dp[p-1][j-1] + (maxv-minv+1)*(maxv-minv+1) - (intersection * intersection)); } } } return dp[k][n]; }
#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...