Submission #527703

# Submission time Handle Problem Language Result Execution time Memory
527703 2022-02-18T04:12:51 Z 8e7 Let's Win the Election (JOI22_ho_t3) C++17
21 / 100
351 ms 2372 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 505
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
pii a[maxn];
const double inf = 1e9;
double dp[maxn][maxn];
int main() {
	io
	int n, k;
	cin >> n >> k;

	for (int i = 0;i < n;i++) {
		cin >> a[i].ff >> a[i].ss; 	
		if (a[i].ss == -1) a[i].ss = 1<<30;
	}
	sort(a, a + n, [&] (pii x, pii y){return (x.ss == y.ss ? x.ff > y.ff : x.ss < y.ss);});
	double ans = 1e9;
	for (int i = 0;i <= k;i++) {
		vector<pii> b;
		for (int j = n-1;j >= i;j--) {
			b.push_back(a[j]);
		}
		sort(b.begin(), b.end());
		vector<pii> v;
		for (int j = 0;j < i;j++) v.push_back(a[j]);
		for (int j = 0;j < k - i;j++) v.push_back(b[j]);
		sort(v.begin(), v.end(), [&](pii x, pii y){return x.ss < y.ss;});

		double tmp = 0;
		for (int j = 0;j < k;j++) tmp += double(v[j].ff) / (i + 1);
		for (int x = 0;x <= k;x++) {
			for (int y = 0;y <= k;y++) dp[x][y] = inf;
		}
		dp[0][0] = 0;
		for (int x = 1;x <= k;x++) {
			for (int y = 0;y <= k;y++) {
				dp[x][y] = dp[x-1][y];
				if (y) {
					dp[x][y] = min(dp[x][y], dp[x-1][y-1] - (double(v[x-1].ff)/(i+1)) + (double)v[x-1].ss/y);
				}
			}
		}
		//debug(i, cur, tmp);
		debug(dp[k][i], tmp);
		ans = min(ans, dp[k][i] + tmp);
	}
	cout << fixed << setprecision(10) << ans << "\n";
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:12:20: warning: statement has no effect [-Wunused-value]
   12 | #define debug(...) 0
      |                    ^
Main.cpp:61:3: note: in expansion of macro 'debug'
   61 |   debug(dp[k][i], tmp);
      |   ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 6 ms 820 KB Output is correct
7 Correct 37 ms 1300 KB Output is correct
8 Correct 113 ms 1796 KB Output is correct
9 Correct 326 ms 2372 KB Output is correct
10 Correct 97 ms 1700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 6 ms 820 KB Output is correct
7 Correct 37 ms 1300 KB Output is correct
8 Correct 113 ms 1796 KB Output is correct
9 Correct 326 ms 2372 KB Output is correct
10 Correct 97 ms 1700 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 12 ms 844 KB Output is correct
13 Correct 10 ms 924 KB Output is correct
14 Correct 11 ms 924 KB Output is correct
15 Correct 113 ms 1696 KB Output is correct
16 Correct 125 ms 1612 KB Output is correct
17 Correct 95 ms 1732 KB Output is correct
18 Correct 351 ms 2296 KB Output is correct
19 Correct 263 ms 2288 KB Output is correct
20 Correct 269 ms 2292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Incorrect 0 ms 332 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Incorrect 0 ms 332 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Incorrect 0 ms 332 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 324 ms 2292 KB Output is correct
2 Correct 310 ms 2296 KB Output is correct
3 Correct 304 ms 2292 KB Output is correct
4 Correct 275 ms 2292 KB Output is correct
5 Correct 276 ms 2252 KB Output is correct
6 Correct 327 ms 2288 KB Output is correct
7 Correct 263 ms 2252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 6 ms 820 KB Output is correct
7 Correct 37 ms 1300 KB Output is correct
8 Correct 113 ms 1796 KB Output is correct
9 Correct 326 ms 2372 KB Output is correct
10 Correct 97 ms 1700 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 12 ms 844 KB Output is correct
13 Correct 10 ms 924 KB Output is correct
14 Correct 11 ms 924 KB Output is correct
15 Correct 113 ms 1696 KB Output is correct
16 Correct 125 ms 1612 KB Output is correct
17 Correct 95 ms 1732 KB Output is correct
18 Correct 351 ms 2296 KB Output is correct
19 Correct 263 ms 2288 KB Output is correct
20 Correct 269 ms 2292 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Incorrect 0 ms 332 KB Output isn't correct
30 Halted 0 ms 0 KB -