Submission #790631

#TimeUsernameProblemLanguageResultExecution timeMemory
790631AmylopectinSalesman (IOI09_salesman)C++14
15 / 100
203 ms65536 KiB
#include <stdio.h> #include <iostream> #include <vector> #include <algorithm> using namespace std; const long long mxn = 2e6 + 10,mni = -1e9 - 10; // const long long mxn = 310,mni = -1e9 - 10; struct we { long long dat,loc,mon; }; bool cmp(const struct we &l,const struct we &r) { return l.loc < r.loc; } struct we sot[mxn] = {}; vector<long long> eve[mxn] = {}; long long val[mxn] = {},dco,uco,sel[mxn] = {},ser[mxn] = {},ale,ari,cval[mxn] = {} ,cvar[mxn] = {},fvap[mxn] = {},ans; long long fimi(long long l,long long r) { if(l < r) { return l; } return r; } long long fima(long long l,long long r) { if(l > r) { return l; } return r; } long long bui(long long cl,long long cr,long long no) { sel[no] = mni; ser[no] = mni; if(cl == cr) { return 0; } long long mid = (cl+cr) / 2; bui(cl,mid,no*2); bui(mid+1,cr,no*2+1); return 0; } long long ad(long long cl,long long cr,long long no,long long tar,long long ava) { if(cl > tar || cr < tar) { return 0; } if(cl == cr) { sel[no] = ava; ser[no] = ava; return 0; } long long mid = (cl+cr) / 2; ad(cl,mid,no*2,tar,ava); ad(mid+1,cr,no*2+1,tar,ava); sel[no] = fima(sel[no*2],sel[no*2+1] - (mid+1 - cl) * uco); ser[no] = fima(ser[no*2+1],ser[no*2] - (cr - mid) * dco); return 0; } long long fiva(long long cl,long long cr,long long no,long long tar) { if(cr < tar) { ale = fima(ale,ser[no] - (tar-cr) * dco); return 0; } if(cl > tar) { ari = fima(ari,sel[no] - (cl - tar) * uco); return 0; } if(cl == cr) { ale = fima(ale,val[cl]); ari = fima(ari,val[cl]); return 0; } long long mid = (cl+cr) / 2; fiva(cl,mid,no*2,tar); fiva(mid+1,cr,no*2+1,tar); return 0; } int main() { long long i,j,n,m = 0,spo,dma = 0,cn,cm,fn,fm,cva; ans = 0; scanf("%lld %lld %lld %lld",&n,&uco,&dco,&spo); for(i=0; i<n; i++) { scanf("%lld %lld %lld",&sot[i].dat,&sot[i].loc,&sot[i].mon); dma = fima(dma,sot[i].dat); } sot[n] = {0,spo,0}; sort(sot,sot + n+1,cmp); m = sot[n].loc; for(i=0; i<n+1; i++) { eve[sot[i].dat].push_back(i); } for(i=0; i<=m; i++) { val[i] = mni; } val[spo] = 0; bui(0,m,1); ad(0,m,1,spo,0); for(i=1; i<=dma; i++) { if(eve[i].size() == 0) { continue; } for(j=0; j<eve[i].size(); j++) { cn = eve[i][j]; ale = mni; ari = mni; fiva(0,m,1,sot[cn].loc); cval[j] = ale + sot[cn].mon; cvar[j] = ari + sot[cn].mon; fvap[j] = val[sot[cn].loc]; if(j != 0) { cval[j] = fima(cval[j],cval[j-1] - (sot[cn].loc - sot[eve[i][j-1]].loc) * dco + sot[cn].mon); } } for(j=eve[i].size()-2; j>=0; j--) { cn = eve[i][j]; { cvar[j] = fima(cvar[j],cvar[j+1] - (sot[eve[i][j+1]].loc - sot[cn].loc) * uco + sot[cn].mon); } } for(j=0; j<eve[i].size(); j++) { cn = eve[i][j]; fvap[j] = fima(cval[j],fima(fvap[j],cvar[j])); ad(0,m,1,sot[cn].loc,fvap[j]); if(sot[cn].loc > spo) { cva = -uco * (sot[cn].loc - spo); } else { cva = -dco * (spo - sot[cn].loc); } ans = fima(ans,fvap[j] + cva); val[sot[cn].loc] = fvap[j]; } } printf("%lld\n",ans); return 0; }

Compilation message (stderr)

salesman.cpp: In function 'int main()':
salesman.cpp:122:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |         for(j=0; j<eve[i].size(); j++)
      |                  ~^~~~~~~~~~~~~~
salesman.cpp:145:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  145 |         for(j=0; j<eve[i].size(); j++)
      |                  ~^~~~~~~~~~~~~~
salesman.cpp:94:42: warning: unused variable 'cm' [-Wunused-variable]
   94 |     long long i,j,n,m = 0,spo,dma = 0,cn,cm,fn,fm,cva;
      |                                          ^~
salesman.cpp:94:45: warning: unused variable 'fn' [-Wunused-variable]
   94 |     long long i,j,n,m = 0,spo,dma = 0,cn,cm,fn,fm,cva;
      |                                             ^~
salesman.cpp:94:48: warning: unused variable 'fm' [-Wunused-variable]
   94 |     long long i,j,n,m = 0,spo,dma = 0,cn,cm,fn,fm,cva;
      |                                                ^~
salesman.cpp:96:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |     scanf("%lld %lld %lld %lld",&n,&uco,&dco,&spo);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
salesman.cpp:99:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |         scanf("%lld %lld %lld",&sot[i].dat,&sot[i].loc,&sot[i].mon);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...