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;
long long take_photos(int n, int m, int g, std::vector<int> r, std::vector<int> c)
{
vector<pair<int ,int>> ranges;
ranges.pb({-1 ,-1});
fore(i ,n)
{
ranges.pb({min(r[i] , c[i]) , max(r[i] , c[i])});
}
sort(ranges.begin() , ranges.end());
ranges.erase(unique(ranges.begin() , ranges.end()) , ranges.end());
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_MAX};
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(0 , ranges[l].second - ranges[l + 1].first + 1)*max(0 , 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... |