Submission #431338

# Submission time Handle Problem Language Result Execution time Memory
431338 2021-06-17T11:04:48 Z errorgorn Long Distance Coach (JOI17_coach) C++17
0 / 100
4 ms 5028 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;
	
	rep(x,0,m) cin>>arr[x].fi>>arr[x].se;
	sort(arr,arr+m);
	
	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,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 4 ms 4940 KB Output is correct
2 Correct 4 ms 5028 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Incorrect 4 ms 4940 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 4 ms 5028 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Incorrect 4 ms 4940 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 4 ms 5028 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Incorrect 4 ms 4940 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 4 ms 5028 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Incorrect 4 ms 4940 KB Output isn't correct
8 Halted 0 ms 0 KB -