Submission #1041098

#TimeUsernameProblemLanguageResultExecution timeMemory
1041098vjudge1Aliens (IOI16_aliens)C++17
0 / 100
1 ms348 KiB
#include "aliens.h" #include<bits/stdc++.h> using namespace std; using lint=int64_t; using pii=pair<lint,lint>; #define pb push_back 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++){ if(c[i]<r[i]){ swap(c[i],r[i]); } } int points[m+1]; memset(points,-1,sizeof(points)); for(int i=0;i<n;i++){ points[r[i]]=max(points[r[i]],c[i]); } vector<pii>pts; for(int i=0;i<=m;i++){ if(points[i]!=-1){ if(!pts.size()||pts.back().second<points[i]){ pts.pb(pii{i,points[i]}); } } } n=pts.size(); lint ans[n][k+1]; ans[0][1]=(pts[0].second-pts[0].first+1)*(pts[0].second-pts[0].first+1); for(int i=1;i<n;i++){ for(int j=2;j<=min(i+1,k);j++){ for(int past=j-1;past<i;past++){ ans[i][j]=ans[i-1][j-1]+(pts[i].second-pts[i].first+1)*(pts[i].second-pts[i].first+1); if(pts[i].first<=pts[past].second){ ans[i][j]-=(pts[past].second-pts[i].first+1)*(pts[past].second-pts[i].first+1); } } } /* for(int j=1;j<=k;j++){ cerr<<ans[i][j]<<" "; } cerr<<"\n"; */ } //cerr<<b[0]<<"\n"; //cerr<<n<<"\n"; lint anss=LLONG_MAX; for(int i=1;i<=min(k,n);i++){ anss=min(anss,ans[n-1][i]); } int i=n-1; for(int j=1;j<=min(i+1,k);j++){ for(int past=j-1;past<i;past++){ lint cur=ans[past][j] +(pts[i].second-pts[past].first+1)*(pts[i].second-pts[past].first+1) -(pts[past].second-pts[past].first+1)*(pts[past].second-pts[past].first+1); anss=min(anss,cur); } } return anss; }
#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...