Submission #21168

#TimeUsernameProblemLanguageResultExecution timeMemory
21168sbansalcsAliens (IOI16_aliens)C++14
25 / 100
163 ms2224 KiB
#include "aliens.h" #include <iostream> #include <algorithm> using namespace std; typedef long long ll; const int N = 4005; const int M = 1e6+2; const ll inf=1e9; // int arr[M]; // int vis[M]; // int cost[N][N]; vector<pair<int,int>> vtx; vector<pair<int,int>> vt; int n2; ll dp[2][N]; 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; } long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) { for(int i=0;i<n;i++) { vtx.push_back({min(r[i],c[i]), max(r[i],c[i])}); } sort(vtx.begin(),vtx.end(),cmp); int s; for(auto c:vtx) { s=vt.size();s--; if(s!=-1 && c.second<=vt[s].second) continue; vt.push_back(c); } int n2=vt.size(); // for(int i=0;i<n;i++) { // if(vt2[i]>vt1[i]) { // swap(vt2[i],vt1[i]); // } // if(vis[vt1[i]]) arr[vt1[i]]=min(arr[vt1[i]],vt2[i]); // else { // arr[vt1[i]]=vt2[i]; // vis[vt1[i]]=1; // vt.push_back(vt1[i]); // } // } // sort(vt.begin(),vt.end()); // int n2=vt.size(); // ll g; // for(int i=0;i<n2;i++) { // cout<<i<<" : "<<vt[i]<<" , "<<arr[vt[i]]<<endl; // } // for(int i=0;i<n2;i++) { // int s=1e7; // for(int j=i;j<n2;j++) { // s=min(arr[vt[j]],s); // cost[i][j]=1+vt[j]-s;cost[i][j]*=cost[i][j]; // cout<<i<<" "<<j<<" : "<<cost[i][j]<<endl; // } // } // for(int i=0;i<n2;i++) { // for(int j=1;j<=i+1 && j<=k;j++) { // if(j==1) // } // } int a,b;ll f,g; for(int i=0;i<=k;i++) { a=i&1;b=a^1; for(int j=0;j<n2;j++) { dp[a][j]=inf; s=1e7; if(i!=0) dp[a][j]=min(dp[a][j],dp[b][j]); if(i!=0 && i<=j+1) { for(int l=j;l>=0;l--) { f=vt[j].second-vt[l].first+1;f*=f; if(l==0) { dp[a][j]=min(dp[a][j],f); } else { g=max(0,vt[l-1].second-vt[l].first+1);g*=g; dp[a][j]=min(dp[a][j],dp[b][l-1]+f-g); } } } // cout<<i<<" "<<j<<" : "<<dp[a][j]<<endl; } } return dp[k&1][n2-1]; }
#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...