This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "aliens.h"
#include <vector>
#include <iostream>
#include <deque>
#include <algorithm>
#define int long long
using namespace std;
int take_photos(signed n, signed m, signed k, vector<signed> r, vector<signed> c)
{
vector<pair<int,int>> intervals;
for (int i = 0; i < n; i++)
{
intervals.push_back({min(r[i], c[i]), -max(r[i], c[i])});
}
sort(intervals.begin(), intervals.end());
vector<int> nl;
vector<int> nr;
int mmx = -1;
for (int i = 0; i < n; i++)
{
if (-intervals[i].second > mmx)
{
nl.push_back(intervals[i].first);
nr.push_back(-intervals[i].second);
mmx = -intervals[i].second;
}
}
int nn = nl.size();
vector<vector<int>> dp(nn + 1, vector<int>(k + 1, 1e9));
dp[0][0] = 0;
for (int i = 1; i <= nn; i++)
{
for (int j = 1; j <= k; j++)
{
dp[i][j] = min(dp[i][j], dp[i][j - 1]);
for (int q = 0; q < i; q++)
{
int ol = 0;
if (q > 0 && nl[q] <= nr[q - 1])
{
ol = nr[q - 1] - nl[q];
ol *= ol;
}
dp[i][j] = min(dp[i][j], dp[q][j - 1] + (nr[i - 1] - nl[i - 1] + 1)*(nr[i - 1] - nl[i - 1] + 1) - ol);
}
}
}
return dp[nn][k];
}
# | 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... |