Submission #127885

# Submission time Handle Problem Language Result Execution time Memory
127885 2019-07-10T07:59:04 Z 김세빈(#3108) Long Distance Coach (JOI17_coach) C++14
100 / 100
209 ms 14036 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;

pll P[202020];
vector <pll> H;
ll X[202020], V[202020];
ll S[202020], dp[202020];
ll x, n, m, w, k, ans;

void addline(ll a, ll b)
{
	ll a1, a2, b1, b2;
	
	for(; H.size() > 1; H.pop_back()){
		tie(a1, b1) = H.back();
		tie(a2, b2) = H[H.size() - 2];
		if((ld)(b - b2) / (a2 - a) > (ld)(b1 - b2) / (a2 - a1)) break;
	}
	
	H.emplace_back(a, b);
}

ll getval(ll x)
{
	ll s, e, mid;
	ll mv, lv, rv;
	
	for(s=0, e=H.size()-1; s<=e; ){
		mid = s + e >> 1;
		mv = H[mid].first * x + H[mid].second;
		lv = mid > 0? H[mid - 1].first * x + H[mid - 1].second : 1e18;
		rv = mid < H.size() - 1? H[mid + 1].first * x + H[mid + 1].second : 1e18;
		if(lv < mv) e = mid - 1;
		else if(rv < mv) s = mid + 1;
		else return mv;
	}
}

int main()
{
	ll i, j, t, s;
	
	scanf("%lld%lld%lld%lld%lld", &x, &n, &m, &w, &k);
	
	for(i=1; i<=n; i++){
		scanf("%lld", X + i);
	}
	
	sort(X + 1, X + n + 1);
	
	X[++n] = x;
	
	for(i=1; i<=m; i++){
		scanf("%lld%lld", &P[i].first, &P[i].second);
		V[i] = -1;
	}
	
	sort(P + 1, P + m + 1);
	
	for(i=1; i<=n; i++){
		t = lower_bound(P + 1, P + m + 1, pll(X[i] % k, 1e18)) - P - 1;
		if(t >= 1){
			if(V[t] == -1) V[t] = X[i] / k;
			else V[t] = min(V[t], X[i] / k);
		}
	}
	
	dp[0] = (x / k + 1) * w;
	addline(0, dp[0]);
	
	for(i=1; i<=m; i++){
		S[i] = S[i - 1] + P[i].second;
		
		if(P[i].first % k < x % k) dp[i] = dp[i - 1] + (x / k + 1) * w;
		else dp[i] = dp[i - 1] + x / k * w;
		
		if(V[i] != -1){
			dp[i] = min(dp[i], getval(V[i]) + S[i] + w * i * V[i]);
		}
		
		addline(-w * i, dp[i] - S[i]);
	}
	
	printf("%lld\n", dp[m]);
	
	return 0;
}

Compilation message

coach.cpp: In function 'll getval(ll)':
coach.cpp:34:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   mid = s + e >> 1;
         ~~^~~
coach.cpp:37:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   rv = mid < H.size() - 1? H[mid + 1].first * x + H[mid + 1].second : 1e18;
        ~~~~^~~~~~~~~~~~~~
coach.cpp: In function 'int main()':
coach.cpp:46:8: warning: unused variable 'j' [-Wunused-variable]
  ll i, j, t, s;
        ^
coach.cpp:46:14: warning: unused variable 's' [-Wunused-variable]
  ll i, j, t, s;
              ^
coach.cpp: In function 'll getval(ll)':
coach.cpp:42:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
coach.cpp: In function 'int main()':
coach.cpp:48:7: 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, &k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", X + i);
   ~~~~~^~~~~~~~~~~~~~~
coach.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &P[i].first, &P[i].second);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 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 372 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 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 372 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 2 ms 376 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 372 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 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 372 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 380 KB Output is correct
24 Correct 2 ms 376 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 376 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 2 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 348 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 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 372 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 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 372 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 380 KB Output is correct
24 Correct 2 ms 376 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 376 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 2 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 348 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 3 ms 504 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 3 ms 504 KB Output is correct
42 Correct 3 ms 380 KB Output is correct
43 Correct 3 ms 376 KB Output is correct
44 Correct 3 ms 504 KB Output is correct
45 Correct 4 ms 504 KB Output is correct
46 Correct 3 ms 420 KB Output is correct
47 Correct 3 ms 504 KB Output is correct
48 Correct 3 ms 376 KB Output is correct
49 Correct 3 ms 376 KB Output is correct
50 Correct 3 ms 376 KB Output is correct
51 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 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 372 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 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 372 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 380 KB Output is correct
24 Correct 2 ms 376 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 376 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 2 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 348 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 3 ms 504 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 3 ms 504 KB Output is correct
42 Correct 3 ms 380 KB Output is correct
43 Correct 3 ms 376 KB Output is correct
44 Correct 3 ms 504 KB Output is correct
45 Correct 4 ms 504 KB Output is correct
46 Correct 3 ms 420 KB Output is correct
47 Correct 3 ms 504 KB Output is correct
48 Correct 3 ms 376 KB Output is correct
49 Correct 3 ms 376 KB Output is correct
50 Correct 3 ms 376 KB Output is correct
51 Correct 3 ms 376 KB Output is correct
52 Correct 204 ms 9664 KB Output is correct
53 Correct 184 ms 10756 KB Output is correct
54 Correct 161 ms 10792 KB Output is correct
55 Correct 162 ms 10744 KB Output is correct
56 Correct 166 ms 10840 KB Output is correct
57 Correct 167 ms 10744 KB Output is correct
58 Correct 171 ms 10744 KB Output is correct
59 Correct 165 ms 10916 KB Output is correct
60 Correct 160 ms 10744 KB Output is correct
61 Correct 162 ms 10776 KB Output is correct
62 Correct 167 ms 10776 KB Output is correct
63 Correct 132 ms 14036 KB Output is correct
64 Correct 146 ms 10740 KB Output is correct
65 Correct 185 ms 10872 KB Output is correct
66 Correct 188 ms 10728 KB Output is correct
67 Correct 184 ms 10844 KB Output is correct
68 Correct 181 ms 10788 KB Output is correct
69 Correct 200 ms 10716 KB Output is correct
70 Correct 209 ms 10884 KB Output is correct
71 Correct 205 ms 10764 KB Output is correct
72 Correct 201 ms 10712 KB Output is correct
73 Correct 202 ms 10704 KB Output is correct
74 Correct 204 ms 10744 KB Output is correct
75 Correct 209 ms 10744 KB Output is correct
76 Correct 205 ms 10712 KB Output is correct
77 Correct 159 ms 10704 KB Output is correct
78 Correct 167 ms 10796 KB Output is correct
79 Correct 197 ms 10740 KB Output is correct
80 Correct 198 ms 10724 KB Output is correct