답안 #1007907

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1007907 2024-06-25T18:40:37 Z beaboss Long Distance Coach (JOI17_coach) C++14
0 / 100
0 ms 348 KB
// Source: https://oj.uz/problem/view/JOI17_coach?locale=en
// 

#include "bits/stdc++.h"

using namespace std;

#define s second
#define f first
#define pb push_back

typedef long long ll;
#define int long long

typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef vector<int> vi;

#define FOR(i, a, b) for (int i = (a); i<b; i++)

bool ckmin(int& a, int b){ return b < a ? a = b, true : false; }

bool ckmax(int& a, int b){ return b > a ? a = b, true : false; }

const int INF = 1e18;

struct Line {
	int m, b;
	int evalX(int x) {
		return m * x + b;
	}
};

deque<Line> line;
void add(Line l) {
	line.push_back(l);
}

int query(int pos) {
	int best = INF;

	for (auto val: line) best = min(best, val.evalX(pos));
	return best;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int x, n, m, w, t;
	cin >> x >> n >> m >> w >> t;
	m++;

	vector<array<int, 3> > all(n + m + 1, {-1, -1, 1});

	FOR(i, 1, n + 1) {
		cin >> all[i][1];
		all[i][0] = all[i][1] % t;
		all[i][2] = 0;
	}	
	FOR(i, n + 1, n + m) cin >> all[i][0] >> all[i][1];	
	all[n + m] = {x % t, x, 0};


	sort(all.begin(), all.end());

	vi prefc(n + m + 1, 0);
	vi cnt(n + m + 1, 0);
	for (int i = 1; i <= n + m; i++) {
		prefc[i] = prefc[i-1] + all[i][1] * all[i][2];
		cnt[i] = cnt[i-1] + all[i][2];
	}
	vi dp(n + m + 1, 0);
	int periods = (x / t);

	for (int i = 1; i <= n + m; i++) {
		// cout << all[i][0] << ' ' << all[i][1] << ' ' << all[i][2] << endl;
		if (all[i][2] == 0) { // refill point
			int skip = (all[i][1] - all[i][0]) / t;
			dp[i] = min(dp[i-1], query(-skip * w) + prefc[i] + skip * w * cnt[i]);

			// for (int j = 0; j < i; j++) {
			// 	int skip = (all[i][1] - all[i][0]) / t;
			// 	ckmin(dp[i], prefc[i] + skip * w * cnt[i] - skip * w * cnt[j] - prefc[j] + dp[j]);
			// }
		} else {
			dp[i] = dp[i-1] + w * (periods + (all[i][0] <= (x % t)));
		}

		add({cnt[i], -prefc[i] + dp[i]});


	}

	cout << dp[n + m] + (periods + 1ll) * w << endl;




}












# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -