답안 #534814

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
534814 2022-03-09T02:58:52 Z 8e7 Long Distance Coach (JOI17_coach) C++17
0 / 100
4 ms 5020 KB
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 200005
#define pii pair<ll, ll>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
const ll inf = 1LL<<60;
ll s[maxn];
pii a[maxn];
ll cost[maxn], pref[maxn];

struct line{
	ll m, k;
	line(){m = 0, k = -inf;}
	line(ll a, ll b){m = a, k = b;}
	ll getval(ll x){return m*x + k;}
};
vector<pii> vec[maxn];
ll dp[maxn];
int main() {
	io
	ll x, n, m, w, t;
	cin >> x >> n >> m >> w >> t;
	for (int i = 1;i <= n;i++) cin >> s[i];	
	for (int i = 0;i < m;i++) {
		cin >> a[i].ff >> a[i].ss;
	}
	sort(a, a + m);
	for (int j = 0;j < m;j++) {
		cost[j] = w * ((x - a[j].ff) / t + 1);
		pref[j] = a[j].ss;
		if (j) cost[j] += cost[j-1], pref[j] += pref[j-1];
	}
	s[n+1] = x;
	for (int i = 0;i <= n;i++) {
		ll lef, rig;
		if (s[i] / t != s[i+1] / t) {
			lef = 1, rig = s[i+1] % t - 1;	
		} else {
			lef = s[i] % t, rig = s[i+1] % t - 1;
		}
		lef = lower_bound(a, a + m, make_pair(lef, (ll)-1)) - a;
		rig = upper_bound(a, a + m, make_pair(rig, 1LL<<60)) - a - 1; //[lef, rig]	

		//debug(lef, rig, s[i+1]/t);
		vec[rig].push_back({lef, s[i+1]/t});
	}
		
	for (int i = 0;i < m;i++) {
		if (i) dp[i] = min(dp[i], dp[i-1]);		
		for (auto [l, h]:vec[i]) {
			for (int j = l - 1;j < i;j++) {
				if (j == -1) {
					dp[i] = min(dp[i], pref[i] - cost[i] + (i-j) * h * w);
					//debug(i, j, cost[i], (i-j)*h*w, pref[i] - cost[i] + (i-j) * h * w);
				} else {
					dp[i] = min(dp[i], dp[j] + pref[i] - pref[j] + cost[j] - cost[i] + (i-j) * h * w);
					//debug(i, j, dp[j] + pref[i] - pref[j] + cost[j] - cost[i] + (i-j) * h * w);
				}
			}
		}
		debug(i, dp[i]);
	}
	cout << dp[m-1] + cost[m-1] + (x / t + 1) * w<< endl;
}

Compilation message

coach.cpp: In function 'int main()':
coach.cpp:12:20: warning: statement has no effect [-Wunused-value]
   12 | #define debug(...) 0
      |                    ^
coach.cpp:76:3: note: in expansion of macro 'debug'
   76 |   debug(i, dp[i]);
      |   ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5016 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 5020 KB Output is correct
4 Correct 4 ms 5016 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 5000 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 2 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 5020 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 2 ms 4940 KB Output is correct
17 Correct 2 ms 4940 KB Output is correct
18 Incorrect 3 ms 4940 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5016 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 5020 KB Output is correct
4 Correct 4 ms 5016 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 5000 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 2 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 5020 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 2 ms 4940 KB Output is correct
17 Correct 2 ms 4940 KB Output is correct
18 Incorrect 3 ms 4940 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5016 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 5020 KB Output is correct
4 Correct 4 ms 5016 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 5000 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 2 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 5020 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 2 ms 4940 KB Output is correct
17 Correct 2 ms 4940 KB Output is correct
18 Incorrect 3 ms 4940 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5016 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 5020 KB Output is correct
4 Correct 4 ms 5016 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 5000 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 2 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 5020 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 2 ms 4940 KB Output is correct
17 Correct 2 ms 4940 KB Output is correct
18 Incorrect 3 ms 4940 KB Output isn't correct
19 Halted 0 ms 0 KB -