답안 #69377

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
69377 2018-08-20T17:11:04 Z hamzqq9 Roller Coaster Railroad (IOI16_railroad) C++14
34 / 100
242 ms 10340 KB
#include "railroad.h"
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define mp(x,y) make_pair(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<int,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 200000000000000000
#define inff 2000000000
#define MOD 1000000007
#define N 200005
#define MAX 10000006
#define LOG 30
#define KOK 200
using namespace std;

ll full;
bool vis[16][pw(16)];
int n;
int pos[N];
ll dp[16][pw(16)];
vector<ii> v[16];
vector<int> rails,s,t;
ii S[N*4];

ii merge(ii x,ii y) {

	if(y.st<x.st) return y;

	return x;

}

void up(int node,int bas,int son,int x) {

	if(bas>x || son<x) return ;

	if(bas==x && son==x) {

		S[node]={inff,-1};

		return ;

	}

	up(node<<1,bas,orta,x);
	up(node<<1|1,orta+1,son,x);

	S[node]=merge(S[node*2],S[node*2+1]);

}

ii get(int node,int bas,int son,int now) {

	if(bas>son || s[rails[son]]<now) return mp(inff,-1);

	if(s[rails[bas]]>=now) return S[node];

	return merge(get(node<<1,bas,orta,now),get(node<<1|1,orta+1,son,now));

}	

void build(int node,int bas,int son) {

	if(bas==son) {

		S[node]={t[rails[bas]],bas};

		return ;

	}

	build(node<<1,bas,orta);
	build(node<<1|1,orta+1,son);

	S[node]=merge(S[node<<1],S[node<<1|1]);

} 

ll S3(vector<int>&ss, vector<int>& tt) {

	n=sz(ss);

	for(int i=0;i<n;i++) s.pb(ss[i]),t.pb(tt[i]);

	for(int i=0;i<n;i++) rails.pb(i);

	sort(all(rails),[](int x,int y) {

		if(s[x]<s[y]) return true;

		if(s[x]>s[y]) return false;

		if(t[x]<t[y]) return true;

		return false;

	});

	build(1,0,n-1);

	int cur_pos=1;

	int total=0;

	while(total<n) {

		ii best=get(1,0,n-1,cur_pos);

		if(best.nd==-1) return 0;

		//cerr<<s[rails[best.nd]]<<' '<<t[rails[best.nd]]<<endl;

		up(1,0,n-1,best.nd);

		cur_pos=best.st;

		total++;

	}

	return 2;

}

ll solve(int now,int mask) {

	if(vis[now][mask]) return dp[now][mask];

	if(mask==full) return 0;

	vis[now][mask]=1;

	ll& r=dp[now][mask];

	r=inf;

	for(int i=0;i<sz(v[now]);i++) {

		if(mask&pw(v[now][i].nd)) continue ;

		umin(r,solve(v[now][i].nd,mask|pw(v[now][i].nd))+v[now][i].st);

	}

	return r;

}

ll S12(vector<int>&s, vector<int>& t) {

	for(int i=0;i<sz(s);i++) {

		for(int j=0;j<sz(s);j++) {

			if(i==j) continue ;

			v[i].pb({max(0,t[i]-s[j]),j});

		}

	}

	full=pw(sz(s))-1;

	ll ans=inf;

	for(int i=0;i<sz(s);i++) {

		umin(ans,solve(i,pw(i)));

	}

	return ans;

}

long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {

	if(sz(s)<=16) return S12(s,t);
	else return S3(s,t);

}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 2
2 Correct 2 ms 376 KB n = 2
3 Correct 2 ms 428 KB n = 2
4 Correct 2 ms 428 KB n = 2
5 Correct 2 ms 488 KB n = 2
6 Correct 2 ms 488 KB n = 2
7 Correct 2 ms 564 KB n = 3
8 Correct 2 ms 620 KB n = 3
9 Correct 2 ms 620 KB n = 3
10 Correct 2 ms 620 KB n = 8
11 Correct 2 ms 620 KB n = 8
12 Correct 2 ms 620 KB n = 8
13 Correct 2 ms 620 KB n = 8
14 Correct 2 ms 620 KB n = 8
15 Correct 2 ms 672 KB n = 8
16 Correct 2 ms 672 KB n = 8
17 Correct 2 ms 672 KB n = 8
18 Correct 2 ms 672 KB n = 8
19 Correct 2 ms 672 KB n = 3
20 Correct 2 ms 672 KB n = 7
21 Correct 2 ms 672 KB n = 8
22 Correct 2 ms 672 KB n = 8
23 Correct 3 ms 672 KB n = 8
24 Correct 3 ms 672 KB n = 8
25 Correct 2 ms 672 KB n = 8
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 2
2 Correct 2 ms 376 KB n = 2
3 Correct 2 ms 428 KB n = 2
4 Correct 2 ms 428 KB n = 2
5 Correct 2 ms 488 KB n = 2
6 Correct 2 ms 488 KB n = 2
7 Correct 2 ms 564 KB n = 3
8 Correct 2 ms 620 KB n = 3
9 Correct 2 ms 620 KB n = 3
10 Correct 2 ms 620 KB n = 8
11 Correct 2 ms 620 KB n = 8
12 Correct 2 ms 620 KB n = 8
13 Correct 2 ms 620 KB n = 8
14 Correct 2 ms 620 KB n = 8
15 Correct 2 ms 672 KB n = 8
16 Correct 2 ms 672 KB n = 8
17 Correct 2 ms 672 KB n = 8
18 Correct 2 ms 672 KB n = 8
19 Correct 2 ms 672 KB n = 3
20 Correct 2 ms 672 KB n = 7
21 Correct 2 ms 672 KB n = 8
22 Correct 2 ms 672 KB n = 8
23 Correct 3 ms 672 KB n = 8
24 Correct 3 ms 672 KB n = 8
25 Correct 2 ms 672 KB n = 8
26 Correct 2 ms 672 KB n = 8
27 Correct 3 ms 696 KB n = 8
28 Correct 2 ms 696 KB n = 8
29 Correct 93 ms 8460 KB n = 16
30 Correct 109 ms 8460 KB n = 16
31 Correct 106 ms 8572 KB n = 16
32 Correct 91 ms 8572 KB n = 16
33 Correct 95 ms 8572 KB n = 16
34 Correct 116 ms 8572 KB n = 16
35 Correct 87 ms 8572 KB n = 16
36 Correct 35 ms 8572 KB n = 15
37 Correct 2 ms 8572 KB n = 8
38 Correct 92 ms 8572 KB n = 16
39 Correct 97 ms 8572 KB n = 16
40 Correct 2 ms 8572 KB n = 9
41 Correct 103 ms 8572 KB n = 16
42 Correct 88 ms 8572 KB n = 16
43 Correct 91 ms 8572 KB n = 16
44 Correct 2 ms 8572 KB n = 9
45 Correct 36 ms 8572 KB n = 15
46 Correct 94 ms 8700 KB n = 16
47 Correct 90 ms 8700 KB n = 16
48 Correct 108 ms 8700 KB n = 16
# 결과 실행 시간 메모리 Grader output
1 Incorrect 242 ms 10340 KB answer is not correct: 1 instead of 0
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 2
2 Correct 2 ms 376 KB n = 2
3 Correct 2 ms 428 KB n = 2
4 Correct 2 ms 428 KB n = 2
5 Correct 2 ms 488 KB n = 2
6 Correct 2 ms 488 KB n = 2
7 Correct 2 ms 564 KB n = 3
8 Correct 2 ms 620 KB n = 3
9 Correct 2 ms 620 KB n = 3
10 Correct 2 ms 620 KB n = 8
11 Correct 2 ms 620 KB n = 8
12 Correct 2 ms 620 KB n = 8
13 Correct 2 ms 620 KB n = 8
14 Correct 2 ms 620 KB n = 8
15 Correct 2 ms 672 KB n = 8
16 Correct 2 ms 672 KB n = 8
17 Correct 2 ms 672 KB n = 8
18 Correct 2 ms 672 KB n = 8
19 Correct 2 ms 672 KB n = 3
20 Correct 2 ms 672 KB n = 7
21 Correct 2 ms 672 KB n = 8
22 Correct 2 ms 672 KB n = 8
23 Correct 3 ms 672 KB n = 8
24 Correct 3 ms 672 KB n = 8
25 Correct 2 ms 672 KB n = 8
26 Correct 2 ms 672 KB n = 8
27 Correct 3 ms 696 KB n = 8
28 Correct 2 ms 696 KB n = 8
29 Correct 93 ms 8460 KB n = 16
30 Correct 109 ms 8460 KB n = 16
31 Correct 106 ms 8572 KB n = 16
32 Correct 91 ms 8572 KB n = 16
33 Correct 95 ms 8572 KB n = 16
34 Correct 116 ms 8572 KB n = 16
35 Correct 87 ms 8572 KB n = 16
36 Correct 35 ms 8572 KB n = 15
37 Correct 2 ms 8572 KB n = 8
38 Correct 92 ms 8572 KB n = 16
39 Correct 97 ms 8572 KB n = 16
40 Correct 2 ms 8572 KB n = 9
41 Correct 103 ms 8572 KB n = 16
42 Correct 88 ms 8572 KB n = 16
43 Correct 91 ms 8572 KB n = 16
44 Correct 2 ms 8572 KB n = 9
45 Correct 36 ms 8572 KB n = 15
46 Correct 94 ms 8700 KB n = 16
47 Correct 90 ms 8700 KB n = 16
48 Correct 108 ms 8700 KB n = 16
49 Incorrect 242 ms 10340 KB answer is not correct: 1 instead of 0
50 Halted 0 ms 0 KB -