제출 #960635

#제출 시각아이디문제언어결과실행 시간메모리
960635lucriAliens (IOI16_aliens)C++17
100 / 100
93 ms8064 KiB
#pragma once #include <bits/stdc++.h> struct intervale{long long b,e;}a[100010]; long long ans[100010],bi,ei; struct slope{long long a,b,cnt;}b[100010]; void elimina(long long x) { while(bi<ei) { if(b[bi].a*x+b[bi].b>b[bi+1].a*x+b[bi+1].b) ++bi; else break; } } void adauga(long long an,long long bn,long long cntn) { while(bi<ei) { ///a*x+b=c*x+d ///x=(d-b)/(a-c) if((b[ei-1].a-b[ei].a)*(bn-b[ei].b)<(b[ei].a-an)*(b[ei].b-b[ei-1].b)) --ei; else break; } b[++ei]={an,bn,cntn}; } bool comp(intervale a,intervale b) { if(a.b!=b.b)return a.b<b.b; return a.e>b.e; } long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) { for(long long i=0;i<n;++i) a[i+1]={std::min(r[i],c[i])+1,std::max(r[i],c[i])+1}; std::sort(a+1,a+n+1,comp); long long poz=1,l2=0; for(long long i=1;i<=n;++i) if(a[i].e>l2) { l2=a[i].e; a[poz++]=a[i]; } n=poz-1; long long bc=0,ec=1LL*m*m; while(bc<=ec) { long long cost=(bc+ec)/2; bi=0,ei=-1; adauga(2-2*a[1].b,a[1].b*a[1].b-2*a[1].b+ans[0],1); for(int i=1;i<=n;++i) { /*for(int ii=1;ii<=i;++ii) ans[i][1]=std::min(ans[i][1],ans[ii-1][0]+(a[i].e-a[ii].b+1)*(a[i].e-a[ii].b+1)-std::max(1LL*0,(a[ii-1].e-a[ii].b+1))*(a[ii-1].e-a[ii].b+1));*/ ///ans[ii-1][0]+(a[i].e-a[ii].b+1)*(a[i].e-a[ii].b+1)-std::max(1LL*0,(a[ii-1].e-a[ii].b+1))*(a[ii-1].e-a[ii].b+1) ///(a[i].e-a[ii].b+1)*(a[i].e-a[ii].b+1) ///a[ii].b^2+1-2*a[ii].b-2*a[i].e*a[ii].b+2*a[i].e+a[i].e^2 ///C=a[ii].b^2-2*a[ii].b+ans[ii-1][0]-std::max(1LL*0,(a[ii-1].e-a[ii].b+1))*(a[ii-1].e-a[ii].b+1) ///C+(2-2*a[ii].b)*a[i].e+a[i].e^2+1 elimina(a[i].e); ans[i]=b[bi].a*a[i].e+b[bi].b; ans[i]+=a[i].e*a[i].e+1+cost; if(i!=n) adauga(2-2*a[i+1].b,a[i+1].b*a[i+1].b-2*a[i+1].b+ans[i]-std::max(1LL*0,(a[i].e-a[i+1].b+1))*(a[i].e-a[i+1].b+1),b[bi].cnt+1); } for(int i=1;i<=n;++i) ans[i]=0; if(b[bi].cnt<=k) ec=cost-1; else bc=cost+1; } long long x,xx,y,yy; bi=0,ei=-1; adauga(2-2*a[1].b,a[1].b*a[1].b-2*a[1].b+ans[0],1); for(int i=1;i<=n;++i) { elimina(a[i].e); ans[i]=b[bi].a*a[i].e+b[bi].b; ans[i]+=a[i].e*a[i].e+1+bc; if(i!=n) adauga(2-2*a[i+1].b,a[i+1].b*a[i+1].b-2*a[i+1].b+ans[i]-std::max(1LL*0,(a[i].e-a[i+1].b+1))*(a[i].e-a[i+1].b+1),b[bi].cnt+1); } x=ans[n]-(b[bi].cnt)*bc; xx=b[bi].cnt; for(int i=1;i<=n;++i) ans[i]=0; bi=0,ei=-1; adauga(2-2*a[1].b,a[1].b*a[1].b-2*a[1].b+ans[0],1); for(int i=1;i<=n;++i) { elimina(a[i].e); ans[i]=b[bi].a*a[i].e+b[bi].b; ans[i]+=a[i].e*a[i].e+1+ec; if(i!=n) adauga(2-2*a[i+1].b,a[i+1].b*a[i+1].b-2*a[i+1].b+ans[i]-std::max(1LL*0,(a[i].e-a[i+1].b+1))*(a[i].e-a[i+1].b+1),b[bi].cnt+1); } y=ans[n]-(b[bi].cnt)*ec; yy=b[bi].cnt; //cnt........val //xx.........x //yy.........y //k..........? if(xx==yy) return x; return x+(k-xx)*(y-x)/(yy-xx); }

컴파일 시 표준 에러 (stderr) 메시지

aliens.cpp:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
#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...