Submission #763735

#TimeUsernameProblemLanguageResultExecution timeMemory
763735mousebeaverAliens (IOI16_aliens)C++17
0 / 100
1 ms224 KiB
#include "aliens.h" #include <bits/stdc++.h> #define ll long long #define INF numeric_limits<ll>::max()/2 #define pll pair<ll, ll> using namespace std; long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) { vector<pll> a(n); for(ll i = 0; i < n; i++) { a[i] = {r[i], c[i]}; if(c[i] < r[i]) //Mirror to diagonal or above { swap(a[i].first, a[i].second); } } sort(a.begin(), a.end()); vector<pll> b(0); for(ll i = 0; i < n; i++) { if((i == n-1 || a[i].first != a[i+1].first) && (b.empty() || a[i].second > b.back().second)) { b.push_back(a[i]); } } a = b; n = a.size(); vector<vector<ll>> dp(n+1, vector<ll> (k+1, INF)); dp[0][0] = 0; for(ll i = 1; i <= n; i++) { for(ll j = 1; j <= k; j++) { dp[i][j] = dp[i][j-1]; for(ll b = 1; b <= i; b++) { ll val = dp[b-1][j-1]; ll root = max(a[i-1].second-a[i-1].first+1, a[b-1].second-a[b-1].first+1); ll area = root*root; //Area of the necessary square to cover the given cells if(b > 1 && a[b-1].first <= a[b-2].second) { //Calculate the overlap with the previous square root = a[b-2].second-a[b-1].first+1; area -= root*root; } val += area; dp[i][j] = min(dp[i][j], val); } } } return dp[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...