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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll solveSubtask1(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
bool grid[m][m];
memset(grid,0, sizeof grid);
for(int i=0; i<n; i++) {
int x = r[i], y = c[i];
if(y < x) swap(x, y);
for(int j=x; j <= y; j++)
for(int k = x; k <= y; k++)
grid[j][k] = 1;
}
int ans = 0;
for(int i=0; i<m; i++)
for(int j=0; j<m; j++)
ans += grid[i][j];
return ans;
}
#define sq(a) ((a) * (a))
ll solveSubtask2(int n, int m, int kk, std::vector<int> r, std::vector<int> c) {
sort(r.begin(), r.end());
r.erase(unique(r.begin(), r.end()), r.end());
ll dp[kk+1][n+1];
memset(dp, 0, sizeof dp);
for(int i=1; i <= n; i++) {
dp[1][i] = sq(r[i-1] - r[0] + 1);
}
for(int k=2; k <= kk; k++) {
for(int i=k; i<=n; i++) {
dp[k][i] = 1e18;
for(int j=0; j < i; j++) {
dp[k][i] = min(dp[k][i], dp[k-1][j] + sq(r[i-1] - r[j] + 1));
}
}
}
ll Min = 1e18;
for(int k = 1; k <= kk; k++)
Min = min(Min, dp[k][n]);
return dp[kk][n];
}
ll take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
if(n <= 50 && m <= 100 && n == k) return solveSubtask1(n, m, k, r, c);
bool f = 0;
for(int i=0; i<n; i++)
if(r[i] != c[i]) { f = 1; break; }
if(!f) return solveSubtask2(n, m, k, r, c);
return 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... |