Submission #562765

#TimeUsernameProblemLanguageResultExecution timeMemory
562765elazarkorenAliens (IOI16_aliens)C++17
0 / 100
1 ms212 KiB
#include "aliens.h"
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;

const int MAX_N = 1e5 + 5;
const ll infinity = 1e18;

ll dp[MAX_N];
int ind[MAX_N];

long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
    for (int i = 0; i < n; i++) {
        if (r[i] > c[i]) swap(r[i], c[i]);
    }
    iota(ind, ind + n, 0);
    sort(ind, ind + n, [&] (int i, int j) {
        return r[i] + c[i] < r[j] + c[j];
    });
    for (int i = 0; i < n; i++) {
        dp[i] = infinity;
        int left = m, right = 0;
        for (int j = i; j >= 0; j--) {
            chkmin(left, r[ind[j]]);
            chkmax(right, c[ind[j]] + 1);
            chkmin(dp[i], (j ? dp[j - 1] : 0) + ll(right - left) * (right - left));
        }
    }
    return dp[n - 1];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...