Submission #549762

#TimeUsernameProblemLanguageResultExecution timeMemory
549762mosiashvililukaAliens (IOI16_aliens)C++14
12 / 100
11 ms404 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,dp[1000009],dp2[1000009],lef,rig,mid; long long bofx[1000009]; pair <long long, long long> p[1000009],pp[1000009]; pair <long long, long long> fun(){ for(i=0; i<=a+1; i++){ dp[i]=a*a+mid*(a+2)+3;dp2[i]=0; } dp[0]=0;dp2[0]=0; for(i=1; i<=a; i++){ if(bofx[i]==0){ dp[i]=dp[i-1];dp2[i]=dp2[i-1]; continue; } dp[i]=i*i+mid;dp2[i]=1; for(ii=0; ii<i; ii++){ //zx=i*i+i*(-2*ii)+(dp[pr[ii]][j-1]-pr[ii]*pr[ii]+2*pr[ii]*ii); if(pr[ii]>ii){ zx=(i-ii)*(i-ii)+dp[pr[ii]]-(pr[ii]-ii)*(pr[ii]-ii)+mid; xc=dp2[ii]+1; }else{ zx=(i-ii)*(i-ii)+dp[pr[ii]]+mid; xc=dp2[ii]+1; } //dp[i][j]=min(dp[i][j],zx); if(dp[i]>zx){ dp[i]=zx;dp2[i]=xc; }else{ if(dp[i]==zx&&dp2[i]>xc){ dp[i]=zx;dp2[i]=xc; } } } } return make_pair(dp[a],dp2[a]); } long long take_photos(int Nn, int Mm, int Kk, std::vector<int> Rr, std::vector<int> Cc) { M=Nn;a=Mm;K=Kk;pas=a*a+4; 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<=K+1; j++){ dp[i][j]=a*a+3; } } dp[0][0]=0; for(i=1; i<=a; i++){ for(j=1; j<=min(i,K); j++){ if(bofx[i]==0){ dp[i][j]=dp[i-1][j]; continue; } dp[i][j]=i*i; for(ii=0; ii<i; ii++){ //zx=i*i+i*(-2*ii)+(dp[pr[ii]][j-1]-pr[ii]*pr[ii]+2*pr[ii]*ii); if(pr[ii]>ii){ zx=(i-ii)*(i-ii)+dp[pr[ii]][j-1]-(pr[ii]-ii)*(pr[ii]-ii); }else{ zx=(i-ii)*(i-ii)+dp[pr[ii]][j-1]; } dp[i][j]=min(dp[i][j],zx); } } } pas=dp[a][1]; for(j=1; j<=K; j++){ pas=min(pas,dp[a][j]); } */ pair <long long, long long> P; mid=0; P=fun(); /*if(P.second<=K){ return P.first; }*/ K=min(K,P.second); lef=0;rig=a*a+4; int EF=0,KL; while(1){ if(lef+1>=rig) break; mid=(lef+rig)/2; P=fun(); if(P.second<=K){ pas=min(pas,P.first-mid*P.second); rig=mid;KL=P.first-mid*K;EF=P.second; }else{ lef=mid; } } if(EF<K){ return KL; } return pas; }

Compilation message (stderr)

aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:114:10: warning: 'KL' may be used uninitialized in this function [-Wmaybe-uninitialized]
  114 |   return KL;
      |          ^~
#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...