Submission #334181

#TimeUsernameProblemLanguageResultExecution timeMemory
334181sebamarinAliens (IOI16_aliens)C++14
25 / 100
180 ms17644 KiB
#include<bits/stdc++.h>
using namespace std;

// #define DEBUG 1
// #define COMPILE 1

typedef long long ll;
typedef pair<ll,ll> ii;
#define db(x) cout<<#x<<" = "<<x<<"\n";
#define fore(i,a,b) for(ll i=a,ggdem=b;i<ggdem;i++)
#define FIN ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define SZ(a) ((ll)(a).size())
#define ALL(a) a.begin(),a.end()
#define mset(a,b) memset(a,b,sizeof(a));
#define pb push_back
#define fst first
#define snd second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ll INF=1e15;
ll n,m,k,dp[1024][1024],wh[1024];
vector<ii>v;
ll sq(ll x){return x*x;}
bool in(ii a,ii b) { // a inside b
  return b.fst<=a.fst && a.snd<=b.snd;
}
ll cost(ll l,ll r,ll mid) { // [l,r] - [m,r]
  ll res=0;
  if (l<=mid && mid<=r)res=sq(r-l+1) - sq(r-mid+1);
  else res=sq(r-l+1);
  #ifdef DEBUG
    cout<<"["<<l<<","<<r<<"] - ["<<mid<<","<<r<<"]: "<<res<<endl;
  #endif
  return res;
}
bool compare(const ii &a,const ii &b) {
  return a.fst<b.fst || (a.fst==b.fst && a.snd>b.snd);
}
ll solve(int i,int j) {
  if(i==n)return 0;
  if(dp[i][j]!=-1)return dp[i][j];
  ll res=INF;
  if(j==k-1) {
    res=cost(v[i].fst,v[n-1].snd,v[n].fst)+solve(n,j);
  } else {
    ll to=-1;
    fore(k,i,n) {
      to=max(to,v[k].snd);
      #ifdef DEBUG
        cout<<i<<","<<j<<" to "<<k<<" : "<<cost(v[i].fst,to,v[k+1].fst)<<"+"<<solve(k+1,j+1)<<" | "<<v[i].fst<<" "<<to<<" "<<v[k+1].fst<<endl;
      #endif
      res=min(res,cost(v[i].fst,to,v[k+1].fst) + solve(k+1,j+1));
    }
  }
  return dp[i][j]=res;
}
vector<ii> get(vector<int> &r,vector<int> &c) {
  vector<ii>v;
  fore(i,0,SZ(r)){
    if(r[i]<=c[i])v.pb({r[i],c[i]});
    else v.pb({c[i],r[i]});
  }
  sort(ALL(v),compare);
  vector<ii>res;
  for(auto it:v) {
    if(!SZ(res) || !in(it,res.back()))res.pb(it);
  }
  return res;
}
ll take_photos(int _n,int _m,int _k,vector<int>r,vector<int> c) {
  n=_n,m=_m,k=_k;
  v=get(r,c);
  n=SZ(v);
  v.pb({INF,INF});
  #ifdef DEBUG
    cout<<"v: "<<endl;for(auto it:v)cout<<it.fst<<" "<<it.snd<<endl;cout<<"n: "<<n<<endl;
  #endif
  memset(dp,-1,sizeof(dp));
  return solve(0,0);
}
#ifdef COMPILE
  int main() {FIN;
  	int n,m,k;
  	cin>>n>>m>>k;
  	vector<int>r(n),c(n);
  	fore(i,0,n)cin>>r[i]>>c[i];
  	cout<<take_photos(n,m,k,r,c)<<"\n";
  }
#endif
/*
5 7 2
0 3
4 4
4 6
4 5
4 6
---> 25
2 5 2
1 4
4 1
---> 16
5 6 4
1 6
1 3
2 4
3 3
5 1
--> 4
*/
#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...