Submission #539793

# Submission time Handle Problem Language Result Execution time Memory
539793 2022-03-19T07:17:06 Z cheissmart Long Distance Coach (JOI17_coach) C++14
100 / 100
205 ms 16956 KB
#include <bits/stdc++.h>
#define IO_OP ios::sync_with_stdio(0), cin.tie(0)
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;
const ll oo = ll(1e18) + 7;

struct line {
	ll m, b;
	line(ll _m, ll _b) : m(_m), b(_b) {}
	ll operator () (ll x) { return m * x + b; }
	ll die(line l) {
		assert(m > l.m);
		return (l.b - b) / (m - l.m) + 1;
	}
};
deque<line> dk;

bool last_is_uesless(line l) {
	if(SZ(dk) < 2) return false;
	return dk[SZ(dk) - 2].die(dk.back()) >= dk.back().die(l);
}

void add(line l) {
	while(last_is_uesless(l)) dk.pop_back();
	dk.PB(l);
}

ll qry(ll x) {
	assert(SZ(dk));
	int lb = 0, rb = SZ(dk) - 2;
	while(lb <= rb) {
		int mb = (lb + rb) / 2;
		if(dk[mb](x) < dk[mb + 1](x))
			rb = mb - 1;
		else
			lb = mb + 1;
	}
	return dk[lb](x);
}

signed main()
{
	IO_OP;

	ll x, t;
	int n, m, w;
	cin >> x >> n >> m >> w >> t;
	V<ll> s(n);
	for(int i = 0; i < n; i++)
		cin >> s[i];
	V<pair<ll, int>> a;
	for(int i = 0; i < m; i++) {
		ll d; int c;
		cin >> d >> c;
		a.EB(d, c);
	}
	sort(ALL(a));
	V<ll> aux(m, oo);
	s.PB(x);
	for(ll ss:s) {
		ll sa = ss / t, na = ss % t;
		int pos = int(upper_bound(ALL(a), MP(na, INF)) - a.begin());
		if(pos > 0)
			aux[pos - 1] = min(aux[pos - 1], sa * w);
	}
	V<ll> p(m + 1);
	for(int i = 0; i < m; i++)
		p[i + 1] = p[i] + a[i].S;
	V<ll> dp(m + 1);
	for(int i = 0; i <= m; i++) {
		if(i == 0) {
			dp[i] = 1LL * (x / t + 1) * w;
		} else {
			dp[i] = dp[i - 1] + 1LL * (x / t + 1 - (a[i - 1].F % t > x % t)) * w;
			if(aux[i - 1] != oo)
				dp[i] = min(dp[i], qry(aux[i - 1]) + i * aux[i - 1] + p[i]);
		}	
		ll m = -i, b = dp[i] - p[i];
		add(line(m, b));
	}
	cout << dp.back() << '\n';
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 2 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 2 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 2 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 336 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 2 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 2 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 2 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 336 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 2 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 124 ms 9696 KB Output is correct
53 Correct 120 ms 15452 KB Output is correct
54 Correct 143 ms 14504 KB Output is correct
55 Correct 152 ms 14736 KB Output is correct
56 Correct 151 ms 15048 KB Output is correct
57 Correct 144 ms 14896 KB Output is correct
58 Correct 158 ms 15500 KB Output is correct
59 Correct 144 ms 14748 KB Output is correct
60 Correct 158 ms 14616 KB Output is correct
61 Correct 205 ms 14752 KB Output is correct
62 Correct 144 ms 14816 KB Output is correct
63 Correct 128 ms 16956 KB Output is correct
64 Correct 109 ms 15604 KB Output is correct
65 Correct 92 ms 15492 KB Output is correct
66 Correct 110 ms 15404 KB Output is correct
67 Correct 96 ms 15392 KB Output is correct
68 Correct 120 ms 15364 KB Output is correct
69 Correct 189 ms 15220 KB Output is correct
70 Correct 150 ms 15224 KB Output is correct
71 Correct 126 ms 15156 KB Output is correct
72 Correct 165 ms 15164 KB Output is correct
73 Correct 146 ms 15188 KB Output is correct
74 Correct 145 ms 15252 KB Output is correct
75 Correct 161 ms 15380 KB Output is correct
76 Correct 172 ms 15384 KB Output is correct
77 Correct 152 ms 15088 KB Output is correct
78 Correct 165 ms 15400 KB Output is correct
79 Correct 138 ms 14772 KB Output is correct
80 Correct 162 ms 14832 KB Output is correct