This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// ItnoE
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 505, MXM = 1e6 + 10;
int n, m, A[N], B[N], MN[MXM];
ll dp[N][N];
inline ll SQR(ll a) {return (a * a);}
int64_t take_photos(int q, int mm, int k, vector < int > RG, vector < int > CG)
{
m = mm;
memset(MN, 63, sizeof(MN));
for (int i = 0; i < q; i ++)
{
if (RG[i] > CG[i])
swap(RG[i], CG[i]);
MN[CG[i]] = min(MN[CG[i]], RG[i]);
}
for (int i = 0; i < m; i ++)
if (MN[i] <= i)
{
int b = i, a = i - MN[i] + 1;
while (n && B[n] - A[n] >= b - a)
n --;
n ++; B[n] = b; A[n] = a;
}
memset(dp, 63, sizeof(dp));
dp[0][0] = 0;
for (int j = 1; j <= k; j ++)
{
for (int i = 1; i <= n; i ++)
{
dp[j][i] = dp[j - 1][i];
for (int h = 1; h <= i; h ++)
{
ll vl = dp[j - 1][h - 1];
vl += SQR(B[i] - B[h] + A[h]);
if (h > 1 && B[h - 1] > B[h] - A[h])
vl -= SQR(B[h - 1] - (B[h] - A[h]));
dp[j][i] = min(dp[j][i], vl);
}
}
}
return (dp[k][n]);
}
/*int main()
{
int q = 2;
int mm = 6;
int k = 2;
vector < int > _R = {1, 4};
vector < int > _C = {4, 1};
ll Res = take_photos(q, mm, k, _R, _C);
cout << Res << endl;
}*/
# | 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... |