Submission #59871

#TimeUsernameProblemLanguageResultExecution timeMemory
59871WA_TLEHoliday (IOI14_holiday)C++14
100 / 100
628 ms25372 KiB
#include<deque> #include<queue> #include<vector> #include<algorithm> #include<iostream> #include<set> #include<cmath> #include<tuple> #include<string> //#include<chrono> #include<functional> #include<iterator> #include<random> #include<unordered_set> #include<array> #include<map> #include<iomanip> #include<assert.h> #include<bitset> #include<stack> using namespace std; typedef long long int llint; typedef long double lldo; #define mp make_pair #define mt make_tuple #define pub push_back #define puf push_front #define pob pop_back #define pof pop_front #define fir first #define sec second #define res resize #define ins insert #define era erase /* cout<<setprecision(20) cin.tie(0); ios::sync_with_stdio(false); */ const llint mod=1e9+7; const llint big=2.19e15+1; const long double pai=3.141592653589793238462643383279502884197; const long double eps=1e-15; template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}} template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}} llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);} //llint lcm(llint a,llint b){return a/gcd(a,b)*b;} template<class T> void SO(T& ve){sort(ve.begin(),ve.end());} template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());} template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();} template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();} /* ioi2014 day2 hoilday 拡張 convex full trick 凸関数とそうでない関数のマージを行う */ //#include"holiday.h" bool dede=false; bool debag=false; vector<llint>pot;//spot,point pair<vector<llint>,vector<llint>>gusolve(int sta,int owa){ //solveのstaからowaまでのマージを行う //愚直~ O(n^2)~ //.firに求めるもの、.secにマージソートで高速化? vector<llint>ans((owa-sta)*2); vector<llint>gen;gen.reserve(owa-sta); int i,j; for(i=0;i<owa-sta;i++){ llint t=pot[i+sta]; int bas=gen.size(); gen.pub(t); while(0<bas&&gen[bas-1]<gen[bas]){ swap(gen[bas-1],gen[bas]); bas--; } llint now=0; for(j=0;j<gen.size();j++){ now+=gen[j]; maxeq(ans[i+j+1],now); } } return mp(ans,gen); } pair<vector<llint>,vector<llint>>solve(int sta,int owa){ if(sta+3>=owa){return gusolve(sta,owa);} int mid=(sta+owa)/2,i,j; auto zehan=solve(sta,mid); vector<llint>ans((owa-sta)*2); for(i=0;i<zehan.fir.size();i++){ans[i]=zehan.fir[i];} //O(nlogn)をさらに分割統治 auto kohan=solve(mid,owa); //zeha.secとkohan.firを拡張convex full trick !!! vector<llint>wa(mid-sta+1+5); for(i=0;i<mid-sta;i++){wa[i+1]=wa[i]+zehan.sec[i];} for(i=mid-sta;i<mid-sta+5;i++){wa[i+1]=wa[i];} // if(debag){ cerr<<"debag wa\n"; for(auto it:wa){cerr<<it<<" ";}cerr<<endl; } vector<pair<int,int>>conb; //conbのback.secは適当でいい auto&ato=kohan.fir;//短く for(i=0;i<ato.size();i++){ if(0<i&&ato[i-1]==ato[i]){continue;} while(conb.size()>=2){ int day=conb[conb.size()-2].sec; int od=conb.back().fir;//old int nd=i;//new if(day<nd){break;} if(wa[day-od]+ato[od]<=wa[day-nd]+ato[nd]){conb.pob();} else{break;} } if(conb.size()>=1){ //ここで二分探索! int bmin=i-1; int bmax=i+wa.size()-2; //等しいときはできるだけ大きく //bminが答え int od=conb.back().fir;//old int nd=i;//new while(bmin+1<bmax){ int bgen=(bmin+bmax)/2; if(wa[bgen-od]+ato[od]<=wa[bgen-nd]+ato[nd]){bmax=bgen;} else{bmin=bgen;} } conb.back().sec=bmax; } conb.pub(mp(i,-1)); if(debag){ cerr<<"i="<<i<<"ato="<<ato[i]<<"dede"; for(auto it:conb){cerr<<it.fir<<':'<<it.sec<<" ";} cerr<<endl; } } conb.back().sec=mod; int bas=0; if(debag){cerr<<"wa.size="<<wa.size()<<endl;} for(i=0;i<ans.size()-mid+sta;i++){ while(conb[bas].sec<=i){bas++;} maxeq(ans[i+mid-sta],wa[min(((int)wa.size())-1,i-conb[bas].fir)]+ato[min(((int)ato.size())-1,conb[bas].fir)]); } vector<llint>gen; merge(zehan.sec.begin(),zehan.sec.end(),kohan.sec.begin(),kohan.sec.end(),back_inserter(gen),greater<llint>()); return mp(ans,gen); } llint findMaxAttraction(int n,int start,int d,int attraction[]){ //初めに左に行く場合と右に行く場合を計算 llint ans=0; if(dede){cerr<<"kokokara"<<endl;debag=true;} pot.resize(n+n+5); llint i; for(i=0;i<=start;i++){pot[i]=attraction[start-i];} vector<llint>hahi=solve(0,start+1).fir; for(i=0;i<n+n+5;i++){pot[i]=0;} for(i=1;i<n-start;i++){pot[2*i]=attraction[i+start];} vector<llint>mdmg=solve(0,(n-start)*2).fir; for(i=0;i<n+n+5;i++){pot[i]=0;} if(hahi.size()==0){hahi.pub(0);} if(mdmg.size()==0){mdmg.pub(0);} for(i=0;i<=d;i++){ llint ge=hahi[min(((llint)hahi.size())-1,i)]+mdmg[min(((llint)mdmg.size())-1,d-i)]; maxeq(ans,ge); } if(debag){cerr<<"chu="<<ans<<endl;} for(i=1;i<=start;i++){pot[2*i]=attraction[start-i];} vector<llint>mdhi=solve(0,(start+1)*2).fir; for(i=0;i<n+n+5;i++){pot[i]=0;} for(i=0;i<n-start;i++){pot[i]=attraction[i+start];} vector<llint>hamg=solve(0,(n-start)).fir; if(mdhi.size()==0){mdhi.pub(0);} if(hamg.size()==0){hamg.pub(0);} for(i=0;i<n+n+5;i++){pot[i]=0;} for(i=0;i<=d;i++){ llint ge=mdhi[min(((llint)mdhi.size())-1,i)]+hamg[min(((llint)hamg.size())-1,d-i)]; maxeq(ans,ge); } return ans; }

Compilation message (stderr)

holiday.cpp: In function 'std::pair<std::vector<long long int>, std::vector<long long int> > gusolve(int, int)':
holiday.cpp:77:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=0;j<gen.size();j++){
           ~^~~~~~~~~~~
holiday.cpp: In function 'std::pair<std::vector<long long int>, std::vector<long long int> > solve(int, int)':
holiday.cpp:89:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<zehan.fir.size();i++){ans[i]=zehan.fir[i];}
          ~^~~~~~~~~~~~~~~~~
holiday.cpp:104:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<ato.size();i++){
          ~^~~~~~~~~~~
holiday.cpp:139:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<ans.size()-mid+sta;i++){
          ~^~~~~~~~~~~~~~~~~~~
holiday.cpp:86:24: warning: unused variable 'j' [-Wunused-variable]
  int mid=(sta+owa)/2,i,j;
                        ^
grader.cpp: In function 'int main()':
grader.cpp:7:12: warning: variable 'n_s' set but not used [-Wunused-but-set-variable]
     int i, n_s;
            ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...