Submission #897977

#TimeUsernameProblemLanguageResultExecution timeMemory
897977JakobZorzAliens (IOI16_aliens)C++17
25 / 100
2051 ms147280 KiB
#include"aliens.h" #include<iostream> #include<algorithm> using namespace std; typedef long long ll; int n; vector<int>l,r; ll dp[5000][5000]; ll sq(ll x){ return x*x; } bool cmp(pair<int,int>a,pair<int,int>b){ if(a.first==b.first) return a.second>b.second; return a.first<b.first; } ll take_photos(int N,int m,int k,vector<int>R,vector<int>C){ n=N; vector<pair<int,int>>intervals_sorted; for(int i=0;i<n;i++){ if(R[i]>C[i]) swap(R[i],C[i]); intervals_sorted.emplace_back(R[i],C[i]); } sort(intervals_sorted.begin(),intervals_sorted.end(),cmp); int right_done=-1; for(auto i:intervals_sorted){ if(i.second>right_done){ l.push_back(i.first); r.push_back(i.second+1); right_done=i.second; } } n=(int)l.size(); /*for(int i=0;i<n;i++) cout<<l[i]<<" "<<r[i]<<"\n";*/ // cheapest way to cover first i segments with j squares for(int i=1;i<=n;i++){ dp[i][0]=1e12; } for(int j=1;j<=k;j++){ for(int i=0;i<=n;i++){ dp[i][j]=dp[i][j-1]; for(int i2=0;i2<i;i2++){ ll curr=sq(r[i-1]-l[i2])+dp[i2][j-1]; if(i2&&r[i2-1]>l[i2]){ curr-=sq(r[i2-1]-l[i2]); } dp[i][j]=min(dp[i][j],curr); } //cout<<"dp["<<i<<"]["<<j<<"] = "<<dp[i][j]<<"\n"; } } return dp[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...