Submission #530323

# Submission time Handle Problem Language Result Execution time Memory
530323 2022-02-25T04:36:30 Z yungyao Let's Win the Election (JOI22_ho_t3) C++17
33 / 100
653 ms 324 KB
using namespace std;
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

typedef long long LL;
typedef pair<int,int> pii;
#define pb push_back
#define mkp make_pair
#define F first
#define S second
#define iter(x) x.begin(),x.end()
#define REP(n) for (int __=n;__--;)
#define REP0(i,n) for (int i=0;i<n;++i)
#define REP1(i,n) for (int i=1;i<=n;++i)

const int maxn = 0, mod = 0;
const LL inf = 0;

#include <iomanip>
void solve2(int n, int k){
	int a[20], b[20];

	REP0(i, n) cin >> a[i] >> b[i];
	double ans = 1e9;
	REP0(mask, 1 << n){
		int m = __builtin_popcount(mask);
		if (m > k) continue;
		bool ok = true;
		REP0(i, n) if (((mask >> i) & 1) and b[i] == -1){
			ok = false;
			break;
		}
		if (!ok) continue;

		vector <int> bs, as;
		REP0(i, n){
			if ((mask >> i) & 1) bs.pb(b[i]);
			else as.pb(a[i]);
		}
		sort(iter(as));
		sort(iter(bs));
		double tans = 0;
		REP0(i, m) tans += bs[i] * 1.0 / (i+1);
		REP0(i, k - m) tans += as[i] * 1.0 / (m+1);
		ans = min(ans, tans);
	}
	cout << ans;
}

void solve(){
	cout << fixed << setprecision(15);
	int n, k;

	cin >> n >> k;
	if (n <= 20){
		solve2(n, k);
		return;
	}
	vector <int> a, b;
	REP(n){
		int aa, bb;

		cin >> aa >> bb;
		if (bb == -1) a.pb(aa);
		else b.pb(aa);
	}
	n = b.size(); int m = a.size();
	sort(iter(a));
	sort(iter(b));
	double ans = 1e9;
	REP0(i, min(n, k)+1){
		if (k - i > m) continue;

		double tans = 0;
		REP0(j, i) tans += b[j] * 1.0 / (j+1);
		REP0(j, k - i) tans += a[j] * 1.0 / (i+1);
		ans = min(ans, tans);
	}
	cout << ans;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);

	solve();

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 220 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 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 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 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 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 4 ms 204 KB Output is correct
17 Correct 245 ms 292 KB Output is correct
18 Correct 67 ms 300 KB Output is correct
19 Correct 578 ms 292 KB Output is correct
20 Correct 66 ms 284 KB Output is correct
21 Correct 38 ms 284 KB Output is correct
22 Correct 605 ms 288 KB Output is correct
23 Correct 64 ms 284 KB Output is correct
24 Correct 13 ms 204 KB Output is correct
25 Correct 653 ms 284 KB Output is correct
26 Correct 203 ms 288 KB Output is correct
27 Correct 592 ms 288 KB Output is correct
28 Correct 598 ms 288 KB Output is correct
29 Correct 593 ms 288 KB Output is correct
30 Correct 625 ms 288 KB Output is correct
31 Correct 588 ms 284 KB Output is correct
32 Correct 614 ms 288 KB Output is correct
33 Correct 580 ms 324 KB Output is correct
34 Correct 581 ms 284 KB Output is correct
35 Correct 606 ms 284 KB Output is correct
36 Correct 587 ms 296 KB Output is correct
37 Correct 625 ms 300 KB Output is correct
38 Correct 556 ms 284 KB Output is correct
39 Correct 646 ms 288 KB Output is correct
40 Correct 651 ms 288 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 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 4 ms 204 KB Output is correct
17 Correct 245 ms 292 KB Output is correct
18 Correct 67 ms 300 KB Output is correct
19 Correct 578 ms 292 KB Output is correct
20 Correct 66 ms 284 KB Output is correct
21 Correct 38 ms 284 KB Output is correct
22 Correct 605 ms 288 KB Output is correct
23 Correct 64 ms 284 KB Output is correct
24 Correct 13 ms 204 KB Output is correct
25 Correct 653 ms 284 KB Output is correct
26 Correct 203 ms 288 KB Output is correct
27 Correct 592 ms 288 KB Output is correct
28 Correct 598 ms 288 KB Output is correct
29 Correct 593 ms 288 KB Output is correct
30 Correct 625 ms 288 KB Output is correct
31 Correct 588 ms 284 KB Output is correct
32 Correct 614 ms 288 KB Output is correct
33 Correct 580 ms 324 KB Output is correct
34 Correct 581 ms 284 KB Output is correct
35 Correct 606 ms 284 KB Output is correct
36 Correct 587 ms 296 KB Output is correct
37 Correct 625 ms 300 KB Output is correct
38 Correct 556 ms 284 KB Output is correct
39 Correct 646 ms 288 KB Output is correct
40 Correct 651 ms 288 KB Output is correct
41 Incorrect 1 ms 204 KB Output isn't correct
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 220 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 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 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 4 ms 204 KB Output is correct
37 Correct 245 ms 292 KB Output is correct
38 Correct 67 ms 300 KB Output is correct
39 Correct 578 ms 292 KB Output is correct
40 Correct 66 ms 284 KB Output is correct
41 Correct 38 ms 284 KB Output is correct
42 Correct 605 ms 288 KB Output is correct
43 Correct 64 ms 284 KB Output is correct
44 Correct 13 ms 204 KB Output is correct
45 Correct 653 ms 284 KB Output is correct
46 Correct 203 ms 288 KB Output is correct
47 Correct 592 ms 288 KB Output is correct
48 Correct 598 ms 288 KB Output is correct
49 Correct 593 ms 288 KB Output is correct
50 Correct 625 ms 288 KB Output is correct
51 Correct 588 ms 284 KB Output is correct
52 Correct 614 ms 288 KB Output is correct
53 Correct 580 ms 324 KB Output is correct
54 Correct 581 ms 284 KB Output is correct
55 Correct 606 ms 284 KB Output is correct
56 Correct 587 ms 296 KB Output is correct
57 Correct 625 ms 300 KB Output is correct
58 Correct 556 ms 284 KB Output is correct
59 Correct 646 ms 288 KB Output is correct
60 Correct 651 ms 288 KB Output is correct
61 Incorrect 1 ms 204 KB Output isn't correct
62 Halted 0 ms 0 KB -