Submission #100094

#TimeUsernameProblemLanguageResultExecution timeMemory
100094owl10124Roller Coaster Railroad (IOI16_railroad)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> //#include "railroad.h" using namespace std; typedef long long ll; typedef pair<int,int> ii; struct seg { int b,m,e,v; seg *l,*r; seg(int nl, int nr) { b=nl,e=nr,m=(nl+nr)/2,v=0; if (b!=e) l=new seg(b,m), r=new seg(m+1,e); } void upd(int p, int nv) { if (b==e) { v=nv; return; } if (p<=m) l->upd(p,nv); else r->upd(p,nv); v=max(l->v,r->v); } ii rmax(int nl, int nr) { if (nl>nr) return make_pair(-1,0); if (b==e) return make_pair(v,b); ii val = make_pair(0,0); if (nl<=m) val=max(val,l->rmax(nl,nr)); if (m<nr) val=max(val,r->rmax(nl,nr)); return val; } }; vector<ii> segs; int n; ll m[16][65536]; ll dp(int seg, int bm) { if (bm==(1<<n)-1) return m[seg][bm]=0; if (seg!=-1&&m[seg][bm]!=-1) return m[seg][bm]; ll l = 1ll<<60; for (int i=0;i<n;i++) { if (((1<<i)&~bm)) l=min(l,(seg!=-1&&segs[seg].second>segs[i].first?segs[seg].second-segs[i].first:0)+dp(i,bm|(1<<i))); } //printf("%d %d %d %lld\n",segs[seg].second,seg,bm,l); return (seg!=-1 ? m[seg][bm]=l : l); } ll plan_roller_coaster(std::vector<int> s, std::vector<int> t) { n = (int) s.size(); for (int i=0;i<n;i++) segs.push_back(make_pair(s[i],t[i])); if (n<=16) { fill(&m[0][0],&m[16][0],-1); return dp(-1,0); } else { //sort by enter speed? then get lowest exit... seg s(0,n-1); sort(segs.begin(),segs.end()); for (int i=0;i<n;i++) s.upd(i,segs[i].second); int rem=n, speed=0; ii buf = s.rmax(0,n-1); s.upd(buf.second,0); while (rem--) { buf = s.rmax(lower_bound(segs.begin(),segs.end(),make_pair(speed,0))-segs.begin(),n-1); //printf("%d %d ",buf.first,buf.second); speed=buf.first; if (speed==-1) return 0; s.upd(buf.second,-1); //printf("%d %d\n",lower_bound(segs.begin(),segs.end(),make_pair(speed,0))-segs.begin(),speed); } return 1; } } int main() { int n; assert(1 == scanf("%d", &n)); std::vector<int> s(n), t(n); for (int i = 0; i < n; ++i) assert(2 == scanf("%d%d", &s[i], &t[i])); long long ans = plan_roller_coaster(s, t); printf("%lld\n", ans); return 0; }

Compilation message (stderr)

railroad.cpp: In function 'll plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:39:35: warning: array subscript is below array bounds [-Warray-bounds]
     if (bm==(1<<n)-1) return m[seg][bm]=0;
                              ~~~~~^
/tmp/ccGQVcaX.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cckMmB2i.o:railroad.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status