제출 #426403

#제출 시각아이디문제언어결과실행 시간메모리
426403ngraceAliens (IOI16_aliens)C++14
25 / 100
151 ms2324 KiB
#include "aliens.h" #include <vector> #include <iostream> #include <utility> #include <algorithm> #include <set> #include <limits.h> using namespace std; #define v vector #define pii pair<int,int> #define fi first #define se second #define ll long long int N,K; v<pii> pos; v<v<long long>> memo; long long diagSolve(int cur, int k){//cover first cur with k photos if(memo[cur][k]!=-1) return memo[cur][k]; if(cur==0) return memo[cur][k] = 0; if(k==0) return LLONG_MAX/2; long long ret=LLONG_MAX/2; for(int i=0;i<cur;i++){ long long curArea=(pos[cur-1].se-pos[i].fi+1) * (pos[cur-1].se-pos[i].fi+1); //check for intersection with prev: if(i!=0){ long long length = max(0, pos[i-1].se-pos[i].fi+1); curArea-=length*length; } long long take = diagSolve(i,k-1); if(take+curArea<ret) ret=take+curArea; } return memo[cur][k] = ret; } long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) { K=k; set<pii> tmp; for(int i=0;i<n;i++){ tmp.insert({min(r[i],c[i]),-max(c[i],r[i])}); } for(pii it:tmp){ if(pos.size()==0) { pos.push_back({it.fi,-it.se}); continue; } if(it.fi<=pos.back().se && -it.se<=pos.back().se) continue; pos.push_back({it.fi,-it.se}); } N=pos.size(); memo=v<v<ll>>(N+1,v<long long>(k+1,-1)); return diagSolve(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...