답안 #541700

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
541700 2022-03-24T08:25:23 Z sidon Long Distance Coach (JOI17_coach) C++17
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
using namespace std;
using ll = __int128_t;

ll read() {
	int64_t x; cin >> x;
	return x;
}

const ll INF = ll(1)<<100;
const int SZ = 2e5+1;

struct Line {
	ll m {}, c {};
	ll operator()(const ll &x) { return m * x + c; }
};

struct LiChaoTree {
	ll l, r; Line v;
	LiChaoTree *L = NULL, *R = NULL;
	LiChaoTree(int lv, int rv) : l(lv), r(rv) {}
	void insert(Line x) {
		ll m = (l + r) >> 1;
		if(v(m) < x(m)) swap(v, x);
		if(r - l < 2) return;

		x.m > v.m ? (R ? : R = new LiChaoTree(m, r))->insert(x):
					(L ? : L = new LiChaoTree(l, m))->insert(x);
	}
	ll operator()(const int &x) {
		if(r - l < 2) return v(x);
		ll m = (l + r) >> 1;
		return x < m ? max(v(x), L ? (*L)(x) : -INF):
					   max(v(x), R ? (*R)(x) : -INF);
	}
};

int N, M;
ll X, W, T, S[SZ], D[SZ], C[SZ];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	X = read(), N = read(), M = read(), W = read(), T = read();

	vector<pair<ll, int>> a(N+M+1);

	for(int i = 0; i < N; ++i) {
		S[i] = read();
		a[i+0] = {S[i] % T, i};
	}
	a[N] = {X % T, N};
	S[N++] = X;

	for(int i = 0; i < M; ++i) {
		D[i] = read(), C[i] = read();
		a[i+N] = {D[i] % T, i + N};
	}

	sort(begin(a), end(a), [](const auto &i, const auto &j) {
		return i.first < j.first;
	});

	LiChaoTree lct(0, X+1);

	ll cost {}, dp[N+M+1] {}, ext = ((X - 1) / T + 1) * W;
	int cnt {};

	for(int i = 1; i <= N + M; ++i) {
		dp[i] = dp[i-1];

		int c = a[i-1].second;
		if(c < N) {
			ll f = (S[c] - ll(1)) / T;
			dp[i] = max(dp[i], cost - f * cnt * W + lct(f));
		} else {
			c -= N; ++cnt;
			ll total = (X / T) + (D[c] <= (X % T));
			ext += total * W;
			cost += total * W - C[c];
		}
		lct.insert(Line{cnt * W, dp[i] - cost});
	}
	cout << int64_t(ext - *max_element(dp, dp + N + M + 1));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Incorrect 0 ms 340 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Incorrect 0 ms 340 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Incorrect 0 ms 340 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Incorrect 0 ms 340 KB Output isn't correct
12 Halted 0 ms 0 KB -