제출 #417896

#제출 시각아이디문제언어결과실행 시간메모리
417896yuto1115Aliens (IOI16_aliens)C++17
25 / 100
87 ms2284 KiB
#include "aliens.h"
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, s, n) for(ll i = ll(s); i < ll(n); i++)
#define rrep(i, n) for(ll i = ll(n)-1; i >= 0; i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

template<class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const int inf = 1001001001;
const ll linf = 1001001001001001001;

ll take_photos(int n, int m, int k, vi r, vi c) {
    vp v;
    rep(i, n) {
        if (r[i] <= c[i]) v.eb(r[i], c[i] + 1);
        else v.eb(c[i], r[i] + 1);
    }
    sort(all(v));
    vi mx(n + 1);
    rep(i, n) mx[i + 1] = max(mx[i], v[i].second);
    vvl dp(n + 1, vl(k + 1, linf));
    dp[0][0] = 0;
    rep(i, n) rep(j, k) {
            ll now = dp[i][j];
            if (now == linf) continue;
            rep2(ni, i, n) {
                if (ni < n - 1 and mx[ni + 2] > v[ni + 1].second) continue;
                ll add = max(0, mx[i] - v[i].first);
                add *= add;
                add = (mx[ni + 1] - v[i].first) * (mx[ni + 1] - v[i].first) - add;
                chmin(dp[ni + 1][j + 1], now + add);
            }
        }
    ll ans = linf;
    rep2(i, 1, k + 1) chmin(ans, dp[n][i]);
    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...