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<iostream>
#include<cstdio>
#include<algorithm>
#define N 4005
#define F first
#define S second
typedef long long ll;
using namespace std;
ll i, j, M, d[N][N];
struct st {
ll ri, ci, z;
} a[N];
bool comp(st p, st q) {
return p.ci < q.ci;
}
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
ll i, j, w, pl, ans, t1, t2, en, mn;
if (n > 500) {
cout << 1/0;
return 0;
}
for (i = n; i >= 1; i--) {
r[i] = r[i - 1];
c[i] = c[i - 1];
}
for (i = 1; i <= n; i++) {
r[i]++;
c[i]++;
if (r[i] > c[i]) swap(r[i], c[i]);
a[i].ri = r[i];
a[i].ci = c[i];
a[i].z = i;
}
a[0].ri = a[0].ci = a[0].z = 0;
sort(a + 1, a + n + 1, comp);
M = m * m;
for (i = 0; i <= n; i++) {
en = i;
if (k < i) en = k;
for (j = 0; j <= en;j++) d[i][j] = M;
}
ans = M;
d[0][0] = 0;
for (i = 1; i <= n; i++) {
en = i;
if (k < i) en = k;
for (j = 1; j <= en; j++) {
d[i][j] = M;
mn = a[i].ri;
for (w = i - 1; w >= j - 1; w--) {
t1 = a[w].ci;
t2 = mn;
pl = max(t1 - t2 + 1, 0ll);
d[i][j] = min(d[i][j], d[w][j - 1] - pl * pl + (a[i].ci - mn + 1) * (a[i].ci - mn + 1));
if (a[w].ri < mn) mn = a[w].ri;
}
if (i == n) ans = min(ans, d[i][j]);
}
}
return ans;
}
Compilation message (stderr)
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:23:12: warning: division by zero [-Wdiv-by-zero]
23 | cout << 1/0;
| ~^~
# | 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... |