제출 #300041

#제출 시각아이디문제언어결과실행 시간메모리
300041MarcoMeijerAliens (IOI16_aliens)C++14
25 / 100
2098 ms141944 KiB
#include "aliens.h"
#include <bits/stdc++.h>

using namespace std;

#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define RE(a,b) REP(a,0,b)
#define FOR(a,b) for(auto& a:b)
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int INF=1e9;
const int MX=5000;

vi r, c, le, ri;
int n, m, k;
int SA[MX];

ll dp[MX][MX];

ll getCost(int i, int j) {
    ll w = ri[j]-le[i]+1;
    ll res = w*w;
    if(j != n-1) {
        ll sw = ri[j]-le[j+1]+1;
        if(sw > 0)
            res -= sw*sw;
    }
    return res;
}
ll getDP(int x, int y) {
    if(dp[x][y] != -1) return dp[x][y];

    ll res = 1e18;
    RE(i,x)
        res = min(res, getCost(i,x-1)+getDP(i,y-1));

    return dp[x][y] = res;
}

ll take_photos(int _n, int _m, int _k, vi _r, vi _c) {
    n=_n; m=_m; k=_k; r=_r; c=_c;
    RE(i,n) if(c[i] < r[i]) swap(c[i], r[i]);
    RE(i,n) SA[i] = i;
    sort(SA,SA+n,[](int i, int j) {
        if(r[i] == r[j]) return c[i] > c[j];
        return r[i] < r[j];
    });
    ll mxr = -1;
    RE(i,n) {
        if(c[SA[i]] <= mxr) continue;
        le.pb(r[SA[i]]);
        ri.pb(c[SA[i]]);
        mxr = c[SA[i]];
    }
    n = le.size();

    RE(i,n+1) RE(j,n+1) dp[i][j] = -1;
    if(k > n) k = n;
    RE(i,n) dp[i][0] = 2e18;
    RE(i,k) dp[0][i] = 0;

    return getDP(n,k);
}
#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...