# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
135730 | ckodser | Aliens (IOI16_aliens) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "aliens.h"
#include<bits/stdc++.h>
#define ll int
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll>
using namespace :: std;
const ll maxn=4100;
const ll maxk=4010;
const ll inf=1e9+900;
const ll logg=20;
ll tav2(ll x){
return x*x;
}
ll mxx[maxn];
ll dp[maxn][maxk];
vector<ll> imp;
ll cost(ll i,ll x){
ll t=findMn(x+1,i);
if(x!=-1 && mx[x]>=t){
return inf;
}if(t>x){
return tav2(i-t+1);
}
return tav2(i-t+1)-tav2(x-t+1);
}
ll mx[maxn];
long long take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
swap(n,m);
fill(mx,mx+maxn,inf);
fill(mxx,mxx+maxn,inf);
for(ll i=0;i<m;i++){
if(c[i]>r[i]){
swap(c[i],r[i]);
}
mx[r[i]]=min(mx[r[i]],(ll)c[i]);
}
stack<ll> stk;
for(ll i=0;i<n;i++){
while(stk.size() && mx[stk.top()]>=mx[i]){
stk.pop();
}
if(mx[i]!=inf){
stk.push(i);
}
}
while(stk.size()){
mxx[stk.top()]=mx[stk.top()];
stk.pop();
}
for(ll i=0;i<n;i++){
if(mxx[i]!=inf)imp.pb(i);
}
for(ll j=1;j<=k;j++){
for(auto i:imp){
dp[i][j]=inf;
for(auto x:imp){
if(x==i)break;
dp[i][j]=min(dp[i][j],dp[x][j-1]+cost(i-1,x-1));
}
if(i==0){
dp[i][j]=0;
}
}
}
return dp[imp.back()][k];
}