This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma once
#include <bits/stdc++.h>
using namespace std;
#define fore(i , n) for(int i = 0;i<n;i++)
#define forr(i , x , y) for(int i = x;i<=y;i++)
#define ll long long
#define pb push_back
const ll INF = 1e18;
bool cmp(const pair<ll , ll> &a , const pair<ll , ll> &b)
{
if(a.first == b.first)
{
return a.second > b.second;
}
return (a.first < b.first);
}
long long take_photos(int n, int m, int g, std::vector<int> r, std::vector<int> c)
{
vector<pair<ll ,ll>> range;
range.pb({-1 ,-1});
fore(i ,n)
{
range.pb({min(r[i] , c[i]) , max(r[i] , c[i])});
}
sort(range.begin() , range.end());
range.erase(unique(range.begin() , range.end()) , range.end());
pair<ll , ll> last = range[1];
vector<pair<ll,ll>> ranges;
ranges.pb({-1 ,-1});
ranges.pb(range[1]);
forr(i , 2 , (int)range.size() - 1)
{
if(range[i].second > last.second)
{
ranges.pb(range[i]);
last = range[i];
}
}
int N = (int)ranges.size() - 1;
g = min(g , N);
ll dp[N + 1][g + 1];
fore(i , N + 1)
fore(j , g + 1)
dp[i][j]= INF;
dp[0][0] = 0;
ranges[0] = {0 , INT_MIN};
forr(i , 1 , N)
{
forr(j , 1 , g)
{
for(int l = 0 ; l < i ; l++)
{
dp[i][j] = min(dp[i][j] , dp[l][j - 1] + (ranges[i].second - ranges[l + 1].first + 1) * (ranges[i].second - ranges[l + 1].first + 1) - max(0ll , ranges[l].second - ranges[l + 1].first + 1)*max(0ll , ranges[l].second - ranges[l + 1].first + 1));
}
}
}
ll ans = INF;
forr(j , 1 , g)
ans = min(ans , dp[N][j]);
return ans;
}
Compilation message (stderr)
aliens.cpp:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |