Submission #431345

# Submission time Handle Problem Language Result Execution time Memory
431345 2021-06-17T11:09:22 Z errorgorn Long Distance Coach (JOI17_coach) C++17
71 / 100
2000 ms 22348 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define endl '\n'

#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound

#define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);s<e?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll l,n,m,w,k;
ll dist[200005];
ii arr[200005];
ll pref[200005];

vector<ii> trans[200005];
ll memo[200005];

int main(){
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(false);
	
	cin>>l>>n>>m>>w>>k;
	
	rep(x,1,n+1) cin>>dist[x];
	dist[n+1]=l;
	sort(dist,dist+n+2);
	
	rep(x,0,m) cin>>arr[x].fi>>arr[x].se;
	sort(arr,arr+m);
	arr[m]=ii(1e9,1e9);
	
	rep(x,0,m) pref[x+1]=pref[x]+arr[x].se;
	
	rep(x,0,n+1){
		//cout<<dist[x]<<" "<<dist[x+1]<<endl;
		
		int l,r;
		
		if ((dist[x]/k+1)*k<=dist[x+1]) l=0;
		else l=lb(arr,arr+m,ii(dist[x]%k,-1))-arr;
		r=lb(arr,arr+m+1,ii(dist[x+1]%k,1e9))-arr-1;
		
		if (l>r) continue;
		
		trans[r].pub(ii(l,(dist[x+1]/k)));
		//cout<<l<<" "<<r<<" "<<(dist[x+1]/k+1)<<endl;
	}
	
	memo[0]=(l/k+1)*w;
	
	rep(x,0,m){
		memo[x+1]=memo[x]+((l-arr[x].fi)/k+1)*w;
		for (auto &it:trans[x]){
			//cout<<endl;
			//cout<<x<<" "<<it.fi<<" "<<it.se<<endl;
			rep(y,it.fi,x+1){
				//cout<<y<<" "<<x<<" "<<(pref[x+1]-pref[y])+(x+1-y)*w*it.se<<endl;
				memo[x+1]=min(memo[x+1],
								memo[y]+(pref[x+1]-pref[y])+(x+1-y)*w*it.se);
			}
		}
	}
	
	cout<<memo[m]<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 4 ms 4960 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 5 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 4 ms 5028 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 4 ms 4940 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 3 ms 5040 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4952 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 4 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 4 ms 4960 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 5 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 4 ms 5028 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 4 ms 4940 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 3 ms 5040 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4952 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 4 ms 4940 KB Output is correct
23 Correct 3 ms 4940 KB Output is correct
24 Correct 3 ms 4940 KB Output is correct
25 Correct 4 ms 5032 KB Output is correct
26 Correct 4 ms 4940 KB Output is correct
27 Correct 5 ms 4940 KB Output is correct
28 Correct 4 ms 4940 KB Output is correct
29 Correct 5 ms 4984 KB Output is correct
30 Correct 4 ms 4940 KB Output is correct
31 Correct 4 ms 5048 KB Output is correct
32 Correct 5 ms 5032 KB Output is correct
33 Correct 4 ms 5056 KB Output is correct
34 Correct 4 ms 5032 KB Output is correct
35 Correct 4 ms 5068 KB Output is correct
36 Correct 4 ms 4940 KB Output is correct
37 Correct 4 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 4 ms 4960 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 5 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 4 ms 5028 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 4 ms 4940 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 3 ms 5040 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4952 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 4 ms 4940 KB Output is correct
23 Correct 3 ms 4940 KB Output is correct
24 Correct 3 ms 4940 KB Output is correct
25 Correct 4 ms 5032 KB Output is correct
26 Correct 4 ms 4940 KB Output is correct
27 Correct 5 ms 4940 KB Output is correct
28 Correct 4 ms 4940 KB Output is correct
29 Correct 5 ms 4984 KB Output is correct
30 Correct 4 ms 4940 KB Output is correct
31 Correct 4 ms 5048 KB Output is correct
32 Correct 5 ms 5032 KB Output is correct
33 Correct 4 ms 5056 KB Output is correct
34 Correct 4 ms 5032 KB Output is correct
35 Correct 4 ms 5068 KB Output is correct
36 Correct 4 ms 4940 KB Output is correct
37 Correct 4 ms 4940 KB Output is correct
38 Correct 10 ms 5164 KB Output is correct
39 Correct 10 ms 5228 KB Output is correct
40 Correct 11 ms 5244 KB Output is correct
41 Correct 10 ms 5204 KB Output is correct
42 Correct 11 ms 5212 KB Output is correct
43 Correct 10 ms 5192 KB Output is correct
44 Correct 15 ms 5164 KB Output is correct
45 Correct 10 ms 5164 KB Output is correct
46 Correct 11 ms 5196 KB Output is correct
47 Correct 14 ms 5232 KB Output is correct
48 Correct 13 ms 5216 KB Output is correct
49 Correct 5 ms 5196 KB Output is correct
50 Correct 11 ms 5204 KB Output is correct
51 Correct 14 ms 5164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 4 ms 4960 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 5 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 4 ms 5028 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 4 ms 4940 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 3 ms 5040 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4952 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 4 ms 4940 KB Output is correct
23 Correct 3 ms 4940 KB Output is correct
24 Correct 3 ms 4940 KB Output is correct
25 Correct 4 ms 5032 KB Output is correct
26 Correct 4 ms 4940 KB Output is correct
27 Correct 5 ms 4940 KB Output is correct
28 Correct 4 ms 4940 KB Output is correct
29 Correct 5 ms 4984 KB Output is correct
30 Correct 4 ms 4940 KB Output is correct
31 Correct 4 ms 5048 KB Output is correct
32 Correct 5 ms 5032 KB Output is correct
33 Correct 4 ms 5056 KB Output is correct
34 Correct 4 ms 5032 KB Output is correct
35 Correct 4 ms 5068 KB Output is correct
36 Correct 4 ms 4940 KB Output is correct
37 Correct 4 ms 4940 KB Output is correct
38 Correct 10 ms 5164 KB Output is correct
39 Correct 10 ms 5228 KB Output is correct
40 Correct 11 ms 5244 KB Output is correct
41 Correct 10 ms 5204 KB Output is correct
42 Correct 11 ms 5212 KB Output is correct
43 Correct 10 ms 5192 KB Output is correct
44 Correct 15 ms 5164 KB Output is correct
45 Correct 10 ms 5164 KB Output is correct
46 Correct 11 ms 5196 KB Output is correct
47 Correct 14 ms 5232 KB Output is correct
48 Correct 13 ms 5216 KB Output is correct
49 Correct 5 ms 5196 KB Output is correct
50 Correct 11 ms 5204 KB Output is correct
51 Correct 14 ms 5164 KB Output is correct
52 Execution timed out 2090 ms 22348 KB Time limit exceeded
53 Halted 0 ms 0 KB -