Submission #531759

#TimeUsernameProblemLanguageResultExecution timeMemory
531759mosiashvililukaAliens (IOI16_aliens)C++14
0 / 100
1 ms428 KiB
#include<bits/stdc++.h> #include "aliens.h" using namespace std; long long a,b,c,d,e,i,j,ii,jj,zx,xc,M,k,pi,pr[1000009],pas,K,B,X; long long bofx[1000009]; pair <long long, long long> p[1000009],pp[1000009]; vector <vector <long long> > dp; deque <pair <long long, long long> > de; long long take_photos(int Nn, int Mm, int Kk, std::vector<int> Rr, std::vector<int> Cc) { M=Nn;a=Mm;k=Kk; dp.resize(a+3); for(i=0; i<a+3; i++){ dp[i].resize(min(k,a)+3); } for(i=1; i<=M; i++){ if(Rr[i-1]>Cc[i-1]) swap(Rr[i-1],Cc[i-1]); pp[i]={Rr[i-1]+1,-Cc[i-1]-1}; } sort(pp+1,pp+M+1); for(i=1; i<=M; i++) pp[i].second=-pp[i].second; for(i=1; i<=M; i++){ if(pi!=0&&p[pi].second>=pp[i].second){ }else{ pi++;p[pi]=pp[i]; } } /*cout<<"rewrew "<<pi<<"\n"; for(i=1; i<=pi; i++) cout<<p[i].first<<" "<<p[i].second<<"\n";*/ for(i=1; i<=pi; i++){ pr[p[i].first]=p[i].second; bofx[p[i].second]=p[i].first; } for(i=1; i<=a; i++){ pr[i]=max(pr[i],pr[i-1]); } for(i=0; i<=a+1; i++){ for(j=0; j<=min(k,a)+1; j++){ dp[i][j]=a*a+3; } } dp[0][0]=0; for(j=1; j<=min(a,k); j++){ de.clear(); for(i=1; i<=a; i++){ ii=i-1; K=(-2LL)*ii;B=dp[pr[ii]][j-1]+ii*ii; if(pr[ii]>ii) B-=(pr[ii]-ii)*(pr[ii]-ii); while(de.size()&&de[0].second>=B) de.pop_front(); while(de.size()>=2){ zx=(de[0].second-B)*(K-de[1].first); xc=(de[1].second-B)*(K-de[0].first); if(zx<=xc){ de.pop_front(); }else{ break; } } de.push_front({K,B}); X=i; while(de.size()>=2){ if(de[0].first*X+de[0].second>de[1].first*X+de[1].second){ de.pop_front(); }else{ break; } } if(bofx[i]==0){ dp[i][j]=dp[i-1][j]; continue; } K=de[0].first;B=de[0].second; dp[i][j]=i*i+K*X+B; } } pas=dp[a][1]; for(j=1; j<=min(a,k); j++){ pas=min(pas,dp[a][j]); } return pas; }
#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...