Submission #127883

# Submission time Handle Problem Language Result Execution time Memory
127883 2019-07-10T07:57:55 Z 김세빈(#3108) Long Distance Coach (JOI17_coach) C++14
16 / 100
2 ms 380 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
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((b - b2) * (a2 - a1) > (b1 - b2) * (a2 - a)) 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:33:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   mid = s + e >> 1;
         ~~^~~
coach.cpp:36: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:45:8: warning: unused variable 'j' [-Wunused-variable]
  ll i, j, t, s;
        ^
coach.cpp:45:14: warning: unused variable 's' [-Wunused-variable]
  ll i, j, t, s;
              ^
coach.cpp: In function 'll getval(ll)':
coach.cpp:41:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
coach.cpp: In function 'int main()':
coach.cpp:47: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:50:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", X + i);
   ~~~~~^~~~~~~~~~~~~~~
coach.cpp:58: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 376 KB Output is correct
9 Correct 2 ms 376 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 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 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 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 376 KB Output is correct
9 Correct 2 ms 376 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 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 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 348 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 296 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 376 KB Output is correct
29 Incorrect 2 ms 376 KB Output isn't correct
30 Halted 0 ms 0 KB -
# 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 376 KB Output is correct
9 Correct 2 ms 376 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 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 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 348 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 296 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 376 KB Output is correct
29 Incorrect 2 ms 376 KB Output isn't correct
30 Halted 0 ms 0 KB -
# 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 376 KB Output is correct
9 Correct 2 ms 376 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 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 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 348 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 296 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 376 KB Output is correct
29 Incorrect 2 ms 376 KB Output isn't correct
30 Halted 0 ms 0 KB -