Submission #887336

# Submission time Handle Problem Language Result Execution time Memory
887336 2023-12-14T09:19:56 Z dubabuba Let's Win the Election (JOI22_ho_t3) C++14
33 / 100
480 ms 600 KB
#include <bits/stdc++.h>
using namespace std;
 
const int inf = 1e9 + 10;
const int mxn = 550;
int a[mxn], n;
int b[mxn], k;
 
vector<int> good;
vector<int> badd;
 
double ans = 1e9;
void solve2(int map) {
	vector<int> vote = badd;
	vector<int> help;
	double ret = 0.0;
 
	for(int i = 0; i < good.size(); i++)
	if(map & (1 << i))
		help.push_back(good[i]);
	else
		vote.push_back(good[i]);
 
	if(help.size() > k) return;
 
	sort(help.begin(), help.end(), [&](int i, int j) { return b[i] < b[j]; });
	sort(vote.begin(), vote.end(), [&](int i, int j) { return a[i] < a[j]; });
 
	int helpers = 0;
	for(int i : help) {
		ret += 1.0 * b[i] / (1.0 + helpers);
		helpers++;
	}
 
	for(int j = 0; j < (k - help.size()); j++) {
		int i = vote[j];
		ret += 1.0 * a[i] / (1.0 + helpers);
	}
 
	ans = min(ans, ret);
}
 
void sub2() {
	for(int bit = 0; bit < (1 << good.size()); bit++)
		solve2(bit);
	cout << setprecision(5) << fixed << ans << '\n';
	exit(0);
}
 
void solve1(int t) {
	// if(k - t >= badd.size()) return;
	double ret = 0.0;
 
	int helpers = 0;
	for(int j = 0; j < t; j++) {
		int i = good[j];
		ret += 1.0 * a[i] / (1.0 + helpers);
		helpers++;
	}

	vector<int> help = badd;
	for(int j = t; j < good.size(); j++)
		help.push_back(good[j]);
	sort(help.begin(), help.end(), [&](int i, int j) { return a[i] < a[j]; });
 
	assert(helpers == t);
	for(int j = 0; j < (k - t); j++) {
		if(j >= help.size())
			return;
		int i = help[j];
		ret += 1.0 * a[i] / (1.0 + t);
	}
 
	ans = min(ans, ret);
}
 
void sub1() {
	sort(good.begin(), good.end(), [&](int i, int j) { return a[i] < a[j]; });
	sort(badd.begin(), badd.end(), [&](int i, int j) { return a[i] < a[j]; });
 
	for(int i = 0; i <= good.size() && i < k; i++)
		solve1(i);
	cout << setprecision(5) << fixed << ans << '\n';
	exit(0);
}
 
int main() {
	cin >> n >> k;
	for(int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		if(b[i] == -1) {
			b[i] = inf;
			badd.push_back(i);
		}
		else
			good.push_back(i);
	}
 
	if(n <= 20) sub2();
	sub1();
	return 0;
}

Compilation message

Main.cpp: In function 'void solve2(int)':
Main.cpp:18:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  for(int i = 0; i < good.size(); i++)
      |                 ~~^~~~~~~~~~~~~
Main.cpp:24:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 |  if(help.size() > k) return;
      |     ~~~~~~~~~~~~^~~
Main.cpp:35:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |  for(int j = 0; j < (k - help.size()); j++) {
      |                 ~~^~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'void solve1(int)':
Main.cpp:62:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |  for(int j = t; j < good.size(); j++)
      |                 ~~^~~~~~~~~~~~~
Main.cpp:68:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   if(j >= help.size())
      |      ~~^~~~~~~~~~~~~~
Main.cpp: In function 'void sub1()':
Main.cpp:81:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |  for(int i = 0; i <= good.size() && i < k; i++)
      |                 ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 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 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 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 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 436 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 3 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 3 ms 448 KB Output is correct
20 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 283 ms 348 KB Output is correct
17 Correct 359 ms 344 KB Output is correct
18 Correct 42 ms 348 KB Output is correct
19 Correct 440 ms 348 KB Output is correct
20 Correct 29 ms 344 KB Output is correct
21 Correct 6 ms 344 KB Output is correct
22 Correct 445 ms 348 KB Output is correct
23 Correct 33 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 480 ms 348 KB Output is correct
26 Correct 114 ms 344 KB Output is correct
27 Correct 462 ms 412 KB Output is correct
28 Correct 431 ms 408 KB Output is correct
29 Correct 448 ms 416 KB Output is correct
30 Correct 453 ms 416 KB Output is correct
31 Correct 444 ms 348 KB Output is correct
32 Correct 465 ms 408 KB Output is correct
33 Correct 453 ms 412 KB Output is correct
34 Correct 439 ms 408 KB Output is correct
35 Correct 448 ms 412 KB Output is correct
36 Correct 445 ms 344 KB Output is correct
37 Correct 452 ms 412 KB Output is correct
38 Correct 442 ms 600 KB Output is correct
39 Correct 469 ms 344 KB Output is correct
40 Correct 466 ms 412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 283 ms 348 KB Output is correct
17 Correct 359 ms 344 KB Output is correct
18 Correct 42 ms 348 KB Output is correct
19 Correct 440 ms 348 KB Output is correct
20 Correct 29 ms 344 KB Output is correct
21 Correct 6 ms 344 KB Output is correct
22 Correct 445 ms 348 KB Output is correct
23 Correct 33 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 480 ms 348 KB Output is correct
26 Correct 114 ms 344 KB Output is correct
27 Correct 462 ms 412 KB Output is correct
28 Correct 431 ms 408 KB Output is correct
29 Correct 448 ms 416 KB Output is correct
30 Correct 453 ms 416 KB Output is correct
31 Correct 444 ms 348 KB Output is correct
32 Correct 465 ms 408 KB Output is correct
33 Correct 453 ms 412 KB Output is correct
34 Correct 439 ms 408 KB Output is correct
35 Correct 448 ms 412 KB Output is correct
36 Correct 445 ms 344 KB Output is correct
37 Correct 452 ms 412 KB Output is correct
38 Correct 442 ms 600 KB Output is correct
39 Correct 469 ms 344 KB Output is correct
40 Correct 466 ms 412 KB Output is correct
41 Incorrect 1 ms 348 KB Output isn't correct
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 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 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 436 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 3 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 3 ms 448 KB Output is correct
20 Correct 2 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 283 ms 348 KB Output is correct
37 Correct 359 ms 344 KB Output is correct
38 Correct 42 ms 348 KB Output is correct
39 Correct 440 ms 348 KB Output is correct
40 Correct 29 ms 344 KB Output is correct
41 Correct 6 ms 344 KB Output is correct
42 Correct 445 ms 348 KB Output is correct
43 Correct 33 ms 348 KB Output is correct
44 Correct 2 ms 348 KB Output is correct
45 Correct 480 ms 348 KB Output is correct
46 Correct 114 ms 344 KB Output is correct
47 Correct 462 ms 412 KB Output is correct
48 Correct 431 ms 408 KB Output is correct
49 Correct 448 ms 416 KB Output is correct
50 Correct 453 ms 416 KB Output is correct
51 Correct 444 ms 348 KB Output is correct
52 Correct 465 ms 408 KB Output is correct
53 Correct 453 ms 412 KB Output is correct
54 Correct 439 ms 408 KB Output is correct
55 Correct 448 ms 412 KB Output is correct
56 Correct 445 ms 344 KB Output is correct
57 Correct 452 ms 412 KB Output is correct
58 Correct 442 ms 600 KB Output is correct
59 Correct 469 ms 344 KB Output is correct
60 Correct 466 ms 412 KB Output is correct
61 Incorrect 1 ms 348 KB Output isn't correct
62 Halted 0 ms 0 KB -