제출 #749816

#제출 시각아이디문제언어결과실행 시간메모리
749816Desh03Aliens (IOI16_aliens)C++17
12 / 100
67 ms2260 KiB
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;

const long long INF = 1e18;

struct point {
    int x, y;
    bool operator < (const point &p) const {
        return x == p.x ? y < p.y : x < p.x;
    }
};

long long take_photos(int n, int m, int k, vector<int> R, vector<int> C) {
    vector<point> f, r;
    for (int i = 0; i < n; i++) f.push_back({R[i], C[i]});
    sort(f.begin(), f.end());
    r.push_back(f[0]);
    for (int i = 1; i < n; i++) {
        if (r.back().x == f[i].x) {
            r.pop_back();
            r.push_back(f[i]);
        } else if (f[i].y > r.back().y) {
            r.push_back(f[i]);
        }
    }
    n = r.size();
    vector<vector<long long>> dp(k, vector<long long> (n, INF));
    for (int i = 0; i < n; i++) dp[0][i] = (long long) (r[i].y - r[0].x + 1) * (r[i].y - r[0].x + 1);
    auto cost = [&] (const int &i, const int &j) {
        long long ext = (r[i].x < r[i - 1].y ? (long long) (r[i - 1].y - r[i].x) * (r[i - 1].y - r[i].x) : 0);
        return (long long) (r[j].y - r[i].x + 1) * (r[j].y - r[i].x + 1) - ext;
    };
    for (int j = 1; j < k; j++)
        for (int i = j; i < n; i++)
            for (int k = 0; k < i; k++)
                dp[j][i] = min(dp[j][i], dp[j - 1][k] + cost(k + 1, i));
    long long ans = INF;
    for (int i = 0; i < k; i++) ans = min(ans, dp[i][n - 1]);
    return ans;
}
#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...