이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 mx[maxn];
ll dp[maxn][maxk];
vector<ll> imp;
ll ff[maxn][logg];
ll tt[maxn];
ll findMn(ll l,ll r){
if(l<0)l=0;
if(r>=maxn)r=maxn-1;
if(l>r)return 0;
ll tol=r-l+1;
return min(ff[l][tt[tol]],ff[r-(1<<tt[tol])+1][tt[tol]]);
}
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);
}
void update(ll j,ll l,ll r,ll L,ll R){
if(l>=r)return;
ll mid=(l+r)/2;
if(mid==0){
dp[imp[0]][j]=0;
return ;
}
pii best=mp(inf,inf);
for(ll i=L;i<R;i++){
best=min(best,mp(dp[imp[i]][j-1]+cost(imp[mid]-1,imp[i]-1),i));
}
dp[imp[mid]][j]=best.F;
if(l+1==r)return;
update(j,l,mid,L,best.S+1);
update(j,mid+1,r,best.S,R);
}
long long take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
swap(n,m);
fill(mx,mx+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]);
}
for(ll i=0;i<n;i++){
ff[i][0]=mx[i];
}
tt[1]=0;
for(ll i=2;i<maxn;i++){
tt[i]=tt[i/2]+1;
}
for(ll i=1;i<logg;i++){
for(ll j=0;j<n;j++){
ll res=j+(1<<(i-1));
if(res>=n){
ff[j][i]=ff[j][i-1];
}else{
ff[j][i]=min(ff[j][i-1],ff[res][i-1]);
}
}
}
imp.pb(0);
for(ll i=1;i<=n;i++){
if(mx[i-1]!=inf)imp.pb(i);
dp[i][0]=inf;
}
for(ll j=1;j<=k;j++){
update(j,0,imp.size(),0,imp.size());
}
return dp[imp.back()][k];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |