Submission #27471

# Submission time Handle Problem Language Result Execution time Memory
27471 2017-07-13T05:55:48 Z khsoo01 Long Distance Coach (JOI17_coach) C++11
100 / 100
253 ms 25332 KB
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
const ll N = 200005, inf = 1e18;

ll x, n, m, w, t, rf[N];
ll sum[N], mn[N];
ld dt[N];
pll a[N];

struct cht {
	vector<pld> v;
	ld val (pld &A, ll &P) {return A.X*P+A.Y;}
	bool valid (pld &A, pld &B, pld &C) {
		return (B.Y-A.Y)*(A.X-C.X) < (C.Y-A.Y)*(A.X-B.X);
	}
	void upd (ld G, ld B) {
		pld T = pld(G, B);
		for(ll i=v.size();i-->1;) {
			if(valid(v[i-1], v[i], T)) break;
			else v.pop_back();
		}
		v.push_back(T);
	}
	ld get (ll P) {
		ll S = 0, E = (ll)v.size()-1;
		while(S<E) {
			ll T = (S+E)/2;
			val(v[T],P)<val(v[T+1],P) ? E = T : S = T+1;
		}
		return val(v[S], P);
	}
} h;

ll cost (ll P) {return (x/t+(x%t>=P))*w;}

int main()
{
	scanf("%lld%lld%lld%lld%lld",&x,&n,&m,&w,&t);
	for(ll i=1;i<=n;i++) scanf("%lld",&rf[i]);
	for(ll i=1;i<=m;i++) scanf("%lld%lld",&a[i].X,&a[i].Y);
	sort(a+1, a+1+m);
	for(ll i=1;i<=m;i++) {
		sum[i] = sum[i-1] + a[i].Y;
		mn[i] = inf;
	}
	rf[n+1] = x;
	for(ll i=1;i<=n+1;i++) {
		ll I = lower_bound(a+1, a+1+m, pll(rf[i]%t, 0)) - a - 1;
		mn[I] = min(mn[I], rf[i]/t);
	}
	dt[0] = cost(0); h.upd(0, dt[0]);
	for(ll i=1;i<=m;i++) {
		dt[i] = dt[i-1]+cost(a[i].X);
		if(mn[i] != inf) dt[i] = min(dt[i], h.get(mn[i])+mn[i]*i*w+sum[i]);
		h.upd(-i*w, dt[i]-sum[i]);
	}
	ll ans = dt[m];
	printf("%lld\n",(dt[m]-ans<0.5?ans:ans+1));
}

Compilation message

coach.cpp: In function 'int main()':
coach.cpp:44:46: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld%lld%lld%lld",&x,&n,&m,&w,&t);
                                              ^
coach.cpp:45:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(ll i=1;i<=n;i++) scanf("%lld",&rf[i]);
                                           ^
coach.cpp:46:56: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(ll i=1;i<=m;i++) scanf("%lld%lld",&a[i].X,&a[i].Y);
                                                        ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 12960 KB Output is correct
2 Correct 0 ms 12960 KB Output is correct
3 Correct 0 ms 12960 KB Output is correct
4 Correct 0 ms 12960 KB Output is correct
5 Correct 0 ms 12960 KB Output is correct
6 Correct 0 ms 12960 KB Output is correct
7 Correct 0 ms 12960 KB Output is correct
8 Correct 0 ms 12960 KB Output is correct
9 Correct 0 ms 12960 KB Output is correct
10 Correct 0 ms 12960 KB Output is correct
11 Correct 0 ms 12960 KB Output is correct
12 Correct 0 ms 12960 KB Output is correct
13 Correct 0 ms 12960 KB Output is correct
14 Correct 0 ms 12960 KB Output is correct
15 Correct 0 ms 12960 KB Output is correct
16 Correct 0 ms 12960 KB Output is correct
17 Correct 0 ms 12960 KB Output is correct
18 Correct 0 ms 12960 KB Output is correct
19 Correct 0 ms 12960 KB Output is correct
20 Correct 0 ms 12960 KB Output is correct
21 Correct 0 ms 12960 KB Output is correct
22 Correct 0 ms 12960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 12960 KB Output is correct
2 Correct 0 ms 12960 KB Output is correct
3 Correct 0 ms 12960 KB Output is correct
4 Correct 0 ms 12960 KB Output is correct
5 Correct 0 ms 12960 KB Output is correct
6 Correct 0 ms 12960 KB Output is correct
7 Correct 0 ms 12960 KB Output is correct
8 Correct 0 ms 12960 KB Output is correct
9 Correct 0 ms 12960 KB Output is correct
10 Correct 0 ms 12960 KB Output is correct
11 Correct 0 ms 12960 KB Output is correct
12 Correct 0 ms 12960 KB Output is correct
13 Correct 0 ms 12960 KB Output is correct
14 Correct 0 ms 12960 KB Output is correct
15 Correct 0 ms 12960 KB Output is correct
16 Correct 0 ms 12960 KB Output is correct
17 Correct 0 ms 12960 KB Output is correct
18 Correct 0 ms 12960 KB Output is correct
19 Correct 0 ms 12960 KB Output is correct
20 Correct 0 ms 12960 KB Output is correct
21 Correct 0 ms 12960 KB Output is correct
22 Correct 0 ms 12960 KB Output is correct
23 Correct 0 ms 12960 KB Output is correct
24 Correct 0 ms 12960 KB Output is correct
25 Correct 0 ms 12960 KB Output is correct
26 Correct 0 ms 12960 KB Output is correct
27 Correct 0 ms 12960 KB Output is correct
28 Correct 0 ms 12960 KB Output is correct
29 Correct 0 ms 12960 KB Output is correct
30 Correct 0 ms 12960 KB Output is correct
31 Correct 0 ms 12960 KB Output is correct
32 Correct 0 ms 12960 KB Output is correct
33 Correct 0 ms 12960 KB Output is correct
34 Correct 0 ms 12960 KB Output is correct
35 Correct 0 ms 12960 KB Output is correct
36 Correct 0 ms 12960 KB Output is correct
37 Correct 0 ms 12960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 12960 KB Output is correct
2 Correct 0 ms 12960 KB Output is correct
3 Correct 0 ms 12960 KB Output is correct
4 Correct 0 ms 12960 KB Output is correct
5 Correct 0 ms 12960 KB Output is correct
6 Correct 0 ms 12960 KB Output is correct
7 Correct 0 ms 12960 KB Output is correct
8 Correct 0 ms 12960 KB Output is correct
9 Correct 0 ms 12960 KB Output is correct
10 Correct 0 ms 12960 KB Output is correct
11 Correct 0 ms 12960 KB Output is correct
12 Correct 0 ms 12960 KB Output is correct
13 Correct 0 ms 12960 KB Output is correct
14 Correct 0 ms 12960 KB Output is correct
15 Correct 0 ms 12960 KB Output is correct
16 Correct 0 ms 12960 KB Output is correct
17 Correct 0 ms 12960 KB Output is correct
18 Correct 0 ms 12960 KB Output is correct
19 Correct 0 ms 12960 KB Output is correct
20 Correct 0 ms 12960 KB Output is correct
21 Correct 0 ms 12960 KB Output is correct
22 Correct 0 ms 12960 KB Output is correct
23 Correct 0 ms 12960 KB Output is correct
24 Correct 0 ms 12960 KB Output is correct
25 Correct 0 ms 12960 KB Output is correct
26 Correct 0 ms 12960 KB Output is correct
27 Correct 0 ms 12960 KB Output is correct
28 Correct 0 ms 12960 KB Output is correct
29 Correct 0 ms 12960 KB Output is correct
30 Correct 0 ms 12960 KB Output is correct
31 Correct 0 ms 12960 KB Output is correct
32 Correct 0 ms 12960 KB Output is correct
33 Correct 0 ms 12960 KB Output is correct
34 Correct 0 ms 12960 KB Output is correct
35 Correct 0 ms 12960 KB Output is correct
36 Correct 0 ms 12960 KB Output is correct
37 Correct 0 ms 12960 KB Output is correct
38 Correct 0 ms 12960 KB Output is correct
39 Correct 0 ms 12960 KB Output is correct
40 Correct 0 ms 12960 KB Output is correct
41 Correct 0 ms 12960 KB Output is correct
42 Correct 0 ms 12960 KB Output is correct
43 Correct 0 ms 12960 KB Output is correct
44 Correct 0 ms 12960 KB Output is correct
45 Correct 0 ms 12960 KB Output is correct
46 Correct 0 ms 13100 KB Output is correct
47 Correct 0 ms 12960 KB Output is correct
48 Correct 0 ms 12960 KB Output is correct
49 Correct 0 ms 12960 KB Output is correct
50 Correct 0 ms 12960 KB Output is correct
51 Correct 0 ms 12960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 12960 KB Output is correct
2 Correct 0 ms 12960 KB Output is correct
3 Correct 0 ms 12960 KB Output is correct
4 Correct 0 ms 12960 KB Output is correct
5 Correct 0 ms 12960 KB Output is correct
6 Correct 0 ms 12960 KB Output is correct
7 Correct 0 ms 12960 KB Output is correct
8 Correct 0 ms 12960 KB Output is correct
9 Correct 0 ms 12960 KB Output is correct
10 Correct 0 ms 12960 KB Output is correct
11 Correct 0 ms 12960 KB Output is correct
12 Correct 0 ms 12960 KB Output is correct
13 Correct 0 ms 12960 KB Output is correct
14 Correct 0 ms 12960 KB Output is correct
15 Correct 0 ms 12960 KB Output is correct
16 Correct 0 ms 12960 KB Output is correct
17 Correct 0 ms 12960 KB Output is correct
18 Correct 0 ms 12960 KB Output is correct
19 Correct 0 ms 12960 KB Output is correct
20 Correct 0 ms 12960 KB Output is correct
21 Correct 0 ms 12960 KB Output is correct
22 Correct 0 ms 12960 KB Output is correct
23 Correct 0 ms 12960 KB Output is correct
24 Correct 0 ms 12960 KB Output is correct
25 Correct 0 ms 12960 KB Output is correct
26 Correct 0 ms 12960 KB Output is correct
27 Correct 0 ms 12960 KB Output is correct
28 Correct 0 ms 12960 KB Output is correct
29 Correct 0 ms 12960 KB Output is correct
30 Correct 0 ms 12960 KB Output is correct
31 Correct 0 ms 12960 KB Output is correct
32 Correct 0 ms 12960 KB Output is correct
33 Correct 0 ms 12960 KB Output is correct
34 Correct 0 ms 12960 KB Output is correct
35 Correct 0 ms 12960 KB Output is correct
36 Correct 0 ms 12960 KB Output is correct
37 Correct 0 ms 12960 KB Output is correct
38 Correct 0 ms 12960 KB Output is correct
39 Correct 0 ms 12960 KB Output is correct
40 Correct 0 ms 12960 KB Output is correct
41 Correct 0 ms 12960 KB Output is correct
42 Correct 0 ms 12960 KB Output is correct
43 Correct 0 ms 12960 KB Output is correct
44 Correct 0 ms 12960 KB Output is correct
45 Correct 0 ms 12960 KB Output is correct
46 Correct 0 ms 13100 KB Output is correct
47 Correct 0 ms 12960 KB Output is correct
48 Correct 0 ms 12960 KB Output is correct
49 Correct 0 ms 12960 KB Output is correct
50 Correct 0 ms 12960 KB Output is correct
51 Correct 0 ms 12960 KB Output is correct
52 Correct 216 ms 12960 KB Output is correct
53 Correct 146 ms 12960 KB Output is correct
54 Correct 196 ms 12960 KB Output is correct
55 Correct 189 ms 12960 KB Output is correct
56 Correct 186 ms 12960 KB Output is correct
57 Correct 183 ms 12960 KB Output is correct
58 Correct 193 ms 12960 KB Output is correct
59 Correct 169 ms 12960 KB Output is correct
60 Correct 163 ms 12960 KB Output is correct
61 Correct 173 ms 12960 KB Output is correct
62 Correct 216 ms 12960 KB Output is correct
63 Correct 156 ms 25332 KB Output is correct
64 Correct 139 ms 12960 KB Output is correct
65 Correct 153 ms 12960 KB Output is correct
66 Correct 136 ms 12960 KB Output is correct
67 Correct 149 ms 12960 KB Output is correct
68 Correct 159 ms 12960 KB Output is correct
69 Correct 206 ms 12960 KB Output is correct
70 Correct 209 ms 12960 KB Output is correct
71 Correct 179 ms 12960 KB Output is correct
72 Correct 223 ms 12960 KB Output is correct
73 Correct 239 ms 12960 KB Output is correct
74 Correct 199 ms 12960 KB Output is correct
75 Correct 196 ms 12960 KB Output is correct
76 Correct 196 ms 12960 KB Output is correct
77 Correct 206 ms 12960 KB Output is correct
78 Correct 196 ms 12960 KB Output is correct
79 Correct 206 ms 12960 KB Output is correct
80 Correct 253 ms 12960 KB Output is correct