이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
}
컴파일 시 표준 에러 (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;
~~~~~^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |