Submission #696084

# Submission time Handle Problem Language Result Execution time Memory
696084 2023-02-05T11:31:38 Z ethening Let's Win the Election (JOI22_ho_t3) C++17
16 / 100
507 ms 3580 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;
	}
	sort(pl.begin() + 1, pl.begin() + n + 1, [](pii& u, pii& v) {
		if (u.second == v.second) return u.first < v.first;
		else return v.second == -1 || u.second < v.second;
	});
	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;
			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);
			}
			// cout << "i: " << i << " j: " << j << " suf[i][j]: " << suffix[i][j] << endl;
		}
	}
	double ans = 1e16;
	for (int coop = 0; coop <= k; coop++) {
		// cout << "###" << coop << endl;
		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 != -1) 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 != -1) {
						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";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 4 ms 688 KB Output is correct
6 Correct 22 ms 1124 KB Output is correct
7 Correct 88 ms 2168 KB Output is correct
8 Correct 218 ms 3080 KB Output is correct
9 Correct 421 ms 3376 KB Output is correct
10 Correct 198 ms 2516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 4 ms 688 KB Output is correct
6 Correct 22 ms 1124 KB Output is correct
7 Correct 88 ms 2168 KB Output is correct
8 Correct 218 ms 3080 KB Output is correct
9 Correct 421 ms 3376 KB Output is correct
10 Correct 198 ms 2516 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 30 ms 1272 KB Output is correct
13 Runtime error 31 ms 1436 KB Execution killed with signal 6
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 507 ms 3492 KB Output is correct
2 Correct 498 ms 3492 KB Output is correct
3 Correct 469 ms 3564 KB Output is correct
4 Correct 492 ms 3540 KB Output is correct
5 Correct 474 ms 3548 KB Output is correct
6 Correct 450 ms 3500 KB Output is correct
7 Correct 504 ms 3580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 4 ms 688 KB Output is correct
6 Correct 22 ms 1124 KB Output is correct
7 Correct 88 ms 2168 KB Output is correct
8 Correct 218 ms 3080 KB Output is correct
9 Correct 421 ms 3376 KB Output is correct
10 Correct 198 ms 2516 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 30 ms 1272 KB Output is correct
13 Runtime error 31 ms 1436 KB Execution killed with signal 6
14 Halted 0 ms 0 KB -