# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1167611 | mychecksedad | Aliens (IOI16_aliens) | C++20 | 0 ms | 0 KiB |
/* Author : Mychecksdead */
#include<bits/stdc++.h>
#include"aliens.h"
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
const int N = 1e5+100, M = 1e5+10, K = 105, MX = 30;
const ll INF = 1e18;
int n, m, k;
array<ll, 2> a[N];
ll dp[N][K], go[N];
ll take_photos(int nn, int mm, int kk, vector<int> r, vi c){
n=nn,m=mm,k=kk;
for(int i=0;i<n;++i) a[i][0]=r[i],a[i][1]=c[i];
/*
cin >> n >> m >> k;
for(int i = 0; i < n; ++i) cin >> a[i][0] >> a[i][1];
*/
for(int i = 0; i < n; ++i){
if(a[i][0] > a[i][1]){
swap(a[i][0], a[i][1]);
}
}
sort(a, a+n, [&](const array<ll,2> &x, const array<ll, 2> &y){
return array<ll,2>{x[1],x[0]}<array<ll,2>{y[1],y[0]};
});
//for(int i = 0; i < n; ++i) cout << a[i][0] << ' ' << a[i][1] << '\n';
ll mn = MOD;
int ptr = n - 1;
for(int i = m; i >= 0; --i){
while(ptr >= 0 && a[ptr][1] >= i){
mn = min(mn, a[ptr][0]);
--ptr;
}
go[i] = mn;
}
//for(int j = 0; j <= m; ++j) cout << go[j] << ' '; en;
for(int j = 0; j <= k; ++j){
for(int i = 0; i <= m; ++i) dp[i][j] = INF;
}
dp[0][0] = 0;
for(int j = 1; j <= k; ++j){
for(int i = 1; i <= m; ++i){
int best = 0;
for(int last = 0; last <= min(i-1, (int)go[i]); ++last){
ll val = dp[last][j - 1] + (go[last] - i) * (go[last] - i) +
(go[last] <= last ? 0ll : - (go[last] - last) * (go[last] - last)));
if(val <= dp[i][j]){
dp[i][j] = val;
best = last;
}
}
best = max(best, int(go[i]));
if(j < k)
dp[i][j] -= (go[i] - i) * (go[i] - i);
//cout << i << ' ' << j << ' ' << dp[i][j] << '\n';
}
//cout << '\n';
}
ll ans = INF;
for(int i = 1; i <= m; ++i) if(go[i] == MOD) ans = min(ans, dp[i][k]);
//cout << ans;
return ans;
}
/*
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int tt = 1, aa;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(tt--){
// solve();
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
return 0;
} */