답안 #743663

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
743663 2023-05-17T16:00:40 Z ethening Let's Win the Election (JOI22_ho_t3) C++17
21 / 100
539 ms 3576 KB
#include "bits/stdc++.h"
#include <functional>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int n, k;
	cin >> n >> k;
	vector<pii> pl(n + 5);
	for (int i = 1; i <= n; i++) {
		cin >> pl[i].first >> pl[i].second;
		if (pl[i].second == -1) pl[i].second = 1e9;
	}
	sort(pl.begin() + 1, pl.begin() + n + 1, [](pii& u, pii& v) {
		if (u.second == v.second) return u.first < v.first;
		else return u.second < v.second;
	});

	// suffix[i][j] = min time cost to get j region in [i, n]
	vector<vector<int>> suffix(n + 5, vector<int>(k + 5, 1e9));
	for (int i = n; i >= 1; i--) {
		for (int j = 0; j <= k; j++) {
			if (j > n - i + 1) break; // j > no. of region in [i, n]
			if (i == n) {
				if (j == 0) suffix[i][j] = 0;
				else if (j == 1) suffix[i][j] = pl[i].first;
			}
			else {
				suffix[i][j] = suffix[i + 1][j];
				if (j > 0) suffix[i][j] = min(suffix[i][j], suffix[i + 1][j - 1] + pl[i].first);
			}
		}
	}

	double ans = 1e16;
	for (int coop = 0; coop <= k; coop++) {
		// cout << "###" << coop << endl;

		// assume will get coop coop-er at the end
		// dp[i][j] = in [1, i], the actual min cost to get j coop-er and (i - j) no-coop region
		vector<vector<double>> dp(n + 5, vector<double>(k + 5, 1e16));
		for (int i = 1; i <= k; i++) {
			for (int j = 0; j <= min(coop, i); j++) {
				if (i == 1) {
					if (j == 0) dp[i][j] = pl[i].first / (coop + 1.0);
					if (j > 0 && pl[i].second != 1e9) dp[i][j] = pl[i].second;
				}
				else {
					dp[i][j] = min(dp[i][j], dp[i - 1][j] + pl[i].first / (coop + 1.0));
					if (j > 0 && pl[i].second != 1e9) {
						dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + pl[i].second / (j - 1 + 1.0));
					}
				}
				// cout << i << " " << j << " " << dp[i][j] << endl;
				if (j == coop) {
					// cout << "@" << i << " " << j << " " << dp[i][j] << " $ " << k - i << " " << suffix[i + 1][k - i] << " " << dp[i][j] + suffix[i + 1][k - i] / (coop + 1.0) << "\n";
					if (i < k) {
						ans = min(ans, dp[i][j] + suffix[i + 1][k - i] / (coop + 1.0));
					}
					else {
						ans = min(ans, dp[i][j]);
					}
				}
			}
		}
	}
	cout << fixed << setprecision(9) << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 3 ms 692 KB Output is correct
6 Correct 21 ms 1132 KB Output is correct
7 Correct 99 ms 1768 KB Output is correct
8 Correct 241 ms 2676 KB Output is correct
9 Correct 419 ms 3572 KB Output is correct
10 Correct 188 ms 2476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 3 ms 692 KB Output is correct
6 Correct 21 ms 1132 KB Output is correct
7 Correct 99 ms 1768 KB Output is correct
8 Correct 241 ms 2676 KB Output is correct
9 Correct 419 ms 3572 KB Output is correct
10 Correct 188 ms 2476 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 31 ms 1276 KB Output is correct
13 Correct 34 ms 1280 KB Output is correct
14 Correct 31 ms 1280 KB Output is correct
15 Correct 200 ms 2524 KB Output is correct
16 Correct 201 ms 2476 KB Output is correct
17 Correct 193 ms 2872 KB Output is correct
18 Correct 480 ms 3520 KB Output is correct
19 Correct 454 ms 3500 KB Output is correct
20 Correct 434 ms 3516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 539 ms 3536 KB Output is correct
2 Correct 477 ms 3548 KB Output is correct
3 Correct 461 ms 3536 KB Output is correct
4 Correct 459 ms 3552 KB Output is correct
5 Correct 470 ms 3576 KB Output is correct
6 Correct 465 ms 3504 KB Output is correct
7 Correct 467 ms 3568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 3 ms 692 KB Output is correct
6 Correct 21 ms 1132 KB Output is correct
7 Correct 99 ms 1768 KB Output is correct
8 Correct 241 ms 2676 KB Output is correct
9 Correct 419 ms 3572 KB Output is correct
10 Correct 188 ms 2476 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 31 ms 1276 KB Output is correct
13 Correct 34 ms 1280 KB Output is correct
14 Correct 31 ms 1280 KB Output is correct
15 Correct 200 ms 2524 KB Output is correct
16 Correct 201 ms 2476 KB Output is correct
17 Correct 193 ms 2872 KB Output is correct
18 Correct 480 ms 3520 KB Output is correct
19 Correct 454 ms 3500 KB Output is correct
20 Correct 434 ms 3516 KB Output is correct
21 Incorrect 0 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -