Submission #127730

# Submission time Handle Problem Language Result Execution time Memory
127730 2019-07-10T04:11:26 Z 구재현(#3116) Long Distance Coach (JOI17_coach) C++14
100 / 100
636 ms 16172 KB
#include <bits/stdc++.h>
typedef long long lint;
typedef long double llf;
using namespace std;
typedef pair<lint, lint> pi;

lint x, n, m, w, t;
lint s[200005], dp[200005], ps[200005];
pi a[200005];
int nxt[200005];

lint get(lint e, lint x){
	return (e - x + t) / t;
}

vector<pi> v;
vector<pi> stk;

llf crs(pi x, pi y){
	return (llf)(y.second - x.second) / (x.first - y.first);
}

void add_line(lint x, lint y){
	stk.insert(lower_bound(stk.begin(), stk.end(), pi(x, y)), pi(x, y));
	if(stk.size() >= 500){
		vector<pi> nxt(v.size() + stk.size());
		merge(v.begin(), v.end(), stk.begin(), stk.end(), nxt.begin());
		v.clear();
		stk.clear();
		for(auto &i : nxt){
			if(!v.empty() && v.back().first == i.first) continue;
			while(v.size() >= 2 && crs(v[v.size()-2], v.back()) < crs(v.back(), i)){
				v.pop_back();
			}
			v.push_back(i);
		}
	}
}

lint query(int x){
	lint ans = 4e18;
	for(auto &i : stk) ans = min(ans, i.first * x + i.second);
	if(!v.empty()){
		int s = 0, e = v.size() - 1;
		while(s != e){
			int m = (s+e)/2;
			if(v[m].first * x + v[m].second < v[m+1].first * x + v[m+1].second) e = m;
			else s = m+1;
		}
		ans = min(ans, v[s].first * x + v[s].second);
	}
	return ans;
}

int main(){
	cin >> x >> n >> m >> w >> t;
	for(int i=0; i<n; i++){
		scanf("%lld",&s[i]);
	}
	s[n] = x;
	n++;
	sort(s, s+n, [&](const lint &a, const lint &b){
		return a%t < b%t;
	});
	for(int i=0; i<m; i++){
		scanf("%lld %lld",&a[i].first,&a[i].second);
	}
	sort(a, a+m);
	for(int i=m-1; i>=0; i--){
		ps[i] = ps[i+1] + a[i].second;
	}
	int p = m;
	for(int i=n-1; i>=0; i--){
		while(p > 0 && a[p-1].first > s[i] % t){
			p--;
		}
		nxt[i] = p;
	}
	lint aux = 0;
	p = n;
	for(int i=m-1; i>=0; i--){
		while(p > 0 && nxt[p-1] == i+1){
			p--;
			dp[p] = aux - ps[i+1];
			add_line((s[p] / t) * w, dp[p] + (s[p] / t) * w * nxt[p]);
		}
		aux += get(x, a[i].first) * w;
		aux = min(aux, query(-i) + ps[i]);
	}
	cout << aux + get(x, 0) * w;
}

Compilation message

coach.cpp: In function 'int main()':
coach.cpp:58:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&s[i]);
   ~~~~~^~~~~~~~~~~~~~
coach.cpp:66:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld",&a[i].first,&a[i].second);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 244 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 404 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 0 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 244 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 404 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 0 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 380 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 504 KB Output is correct
28 Correct 2 ms 380 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 244 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 404 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 0 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 380 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 504 KB Output is correct
28 Correct 2 ms 380 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 5 ms 504 KB Output is correct
39 Correct 4 ms 504 KB Output is correct
40 Correct 5 ms 504 KB Output is correct
41 Correct 4 ms 504 KB Output is correct
42 Correct 5 ms 504 KB Output is correct
43 Correct 5 ms 504 KB Output is correct
44 Correct 5 ms 632 KB Output is correct
45 Correct 4 ms 504 KB Output is correct
46 Correct 5 ms 504 KB Output is correct
47 Correct 5 ms 504 KB Output is correct
48 Correct 6 ms 508 KB Output is correct
49 Correct 5 ms 504 KB Output is correct
50 Correct 5 ms 504 KB Output is correct
51 Correct 5 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 244 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 404 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 0 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 380 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 504 KB Output is correct
28 Correct 2 ms 380 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 5 ms 504 KB Output is correct
39 Correct 4 ms 504 KB Output is correct
40 Correct 5 ms 504 KB Output is correct
41 Correct 4 ms 504 KB Output is correct
42 Correct 5 ms 504 KB Output is correct
43 Correct 5 ms 504 KB Output is correct
44 Correct 5 ms 632 KB Output is correct
45 Correct 4 ms 504 KB Output is correct
46 Correct 5 ms 504 KB Output is correct
47 Correct 5 ms 504 KB Output is correct
48 Correct 6 ms 508 KB Output is correct
49 Correct 5 ms 504 KB Output is correct
50 Correct 5 ms 504 KB Output is correct
51 Correct 5 ms 504 KB Output is correct
52 Correct 346 ms 14652 KB Output is correct
53 Correct 353 ms 14712 KB Output is correct
54 Correct 322 ms 13840 KB Output is correct
55 Correct 320 ms 14200 KB Output is correct
56 Correct 325 ms 14380 KB Output is correct
57 Correct 307 ms 14244 KB Output is correct
58 Correct 325 ms 14584 KB Output is correct
59 Correct 331 ms 14104 KB Output is correct
60 Correct 318 ms 13852 KB Output is correct
61 Correct 324 ms 14072 KB Output is correct
62 Correct 318 ms 14072 KB Output is correct
63 Correct 636 ms 16172 KB Output is correct
64 Correct 184 ms 13176 KB Output is correct
65 Correct 422 ms 14716 KB Output is correct
66 Correct 409 ms 14660 KB Output is correct
67 Correct 412 ms 14780 KB Output is correct
68 Correct 411 ms 14712 KB Output is correct
69 Correct 345 ms 14636 KB Output is correct
70 Correct 348 ms 14484 KB Output is correct
71 Correct 346 ms 14420 KB Output is correct
72 Correct 340 ms 14464 KB Output is correct
73 Correct 343 ms 14444 KB Output is correct
74 Correct 350 ms 14476 KB Output is correct
75 Correct 347 ms 14544 KB Output is correct
76 Correct 344 ms 14680 KB Output is correct
77 Correct 341 ms 14332 KB Output is correct
78 Correct 346 ms 14580 KB Output is correct
79 Correct 343 ms 14064 KB Output is correct
80 Correct 342 ms 14060 KB Output is correct