Submission #914335

# Submission time Handle Problem Language Result Execution time Memory
914335 2024-01-21T16:50:14 Z Trisanu_Das Long Distance Coach (JOI17_coach) C++17
100 / 100
111 ms 25028 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:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |  scanf("%lld%lld%lld%lld%lld",&x,&n,&m,&w,&t);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:45:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |  for(ll i=1;i<=n;i++) scanf("%lld",&rf[i]);
      |                       ~~~~~^~~~~~~~~~~~~~~
coach.cpp:46:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |  for(ll i=1;i<=m;i++) scanf("%lld%lld",&a[i].X,&a[i].Y);
      |                       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6600 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 2 ms 6588 KB Output is correct
22 Correct 2 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6600 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 2 ms 6588 KB Output is correct
22 Correct 2 ms 6488 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 2 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 1 ms 6488 KB Output is correct
35 Correct 1 ms 6492 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6600 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 2 ms 6588 KB Output is correct
22 Correct 2 ms 6488 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 2 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 1 ms 6488 KB Output is correct
35 Correct 1 ms 6492 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 2 ms 6492 KB Output is correct
40 Correct 2 ms 6492 KB Output is correct
41 Correct 2 ms 6492 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 2 ms 6492 KB Output is correct
44 Correct 2 ms 6492 KB Output is correct
45 Correct 2 ms 6492 KB Output is correct
46 Correct 2 ms 6748 KB Output is correct
47 Correct 2 ms 6492 KB Output is correct
48 Correct 2 ms 6488 KB Output is correct
49 Correct 2 ms 6492 KB Output is correct
50 Correct 2 ms 6492 KB Output is correct
51 Correct 2 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6600 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 2 ms 6588 KB Output is correct
22 Correct 2 ms 6488 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 2 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 1 ms 6488 KB Output is correct
35 Correct 1 ms 6492 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 2 ms 6492 KB Output is correct
40 Correct 2 ms 6492 KB Output is correct
41 Correct 2 ms 6492 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 2 ms 6492 KB Output is correct
44 Correct 2 ms 6492 KB Output is correct
45 Correct 2 ms 6492 KB Output is correct
46 Correct 2 ms 6748 KB Output is correct
47 Correct 2 ms 6492 KB Output is correct
48 Correct 2 ms 6488 KB Output is correct
49 Correct 2 ms 6492 KB Output is correct
50 Correct 2 ms 6492 KB Output is correct
51 Correct 2 ms 6492 KB Output is correct
52 Correct 111 ms 16900 KB Output is correct
53 Correct 83 ms 16980 KB Output is correct
54 Correct 96 ms 16644 KB Output is correct
55 Correct 97 ms 16468 KB Output is correct
56 Correct 99 ms 16700 KB Output is correct
57 Correct 97 ms 16536 KB Output is correct
58 Correct 100 ms 16980 KB Output is correct
59 Correct 98 ms 16468 KB Output is correct
60 Correct 102 ms 16168 KB Output is correct
61 Correct 98 ms 16452 KB Output is correct
62 Correct 98 ms 16216 KB Output is correct
63 Correct 96 ms 25028 KB Output is correct
64 Correct 64 ms 16980 KB Output is correct
65 Correct 76 ms 16936 KB Output is correct
66 Correct 76 ms 16980 KB Output is correct
67 Correct 79 ms 17004 KB Output is correct
68 Correct 78 ms 16940 KB Output is correct
69 Correct 103 ms 16740 KB Output is correct
70 Correct 106 ms 16868 KB Output is correct
71 Correct 102 ms 16856 KB Output is correct
72 Correct 105 ms 16732 KB Output is correct
73 Correct 105 ms 16728 KB Output is correct
74 Correct 107 ms 16816 KB Output is correct
75 Correct 103 ms 17024 KB Output is correct
76 Correct 105 ms 17088 KB Output is correct
77 Correct 97 ms 16604 KB Output is correct
78 Correct 106 ms 17044 KB Output is correct
79 Correct 101 ms 16468 KB Output is correct
80 Correct 103 ms 16476 KB Output is correct