Submission #921305

# Submission time Handle Problem Language Result Execution time Memory
921305 2024-02-03T16:47:54 Z KiaRez Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
1169 ms 12888 KB
/*
    IN THE NAME OF GOD
*/
#include <bits/stdc++.h>

// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;

#define F                                      first
#define S                                      second
#define Mp                                     make_pair
#define pb                                     push_back
#define pf                                     push_front
#define size(x)                                ((ll)x.size())
#define all(x)                                 (x).begin(),(x).end()
#define kill(x)		                           cout << x << '\n', exit(0);
#define fuck(x)                                cout << "(" << #x << " , " << x << ")" << endl
#define endl                                   '\n'

const int N = 3e5+23, lg = 18;
ll Mod = 1e9+7; //998244353;

inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
    ll ans = 1;
    a=MOD(a, mod);
    while (b) {
        if (b & 1) ans = MOD(ans*a, mod);
        b >>= 1;
        a = MOD(a*a, mod);
    }
    return ans;
}

int n, k, A[N], B[N];
ld dp[505][505], pd[505][505];
pair<ld, ld> x[N], y[N];

ld check(int mid) {
	for(int i=0; i<=n; i++) fill(dp[i], dp[i]+k+2, 1e9);
	ld ans = 1e9;
	dp[0][0] = 0;
	for(int i=1; i<=n; i++) {
	for(int j=0; j<=i&&j<=k; j++) {
		if(j>0) dp[i][j] = min(dp[i][j], dp[i-1][j-1]+x[i].F/(ld)(j));
		dp[i][j] = min(dp[i][j], dp[i-1][j]+x[i].S/(ld)(mid+1));
	}
	if(k>=i) {
		ans = min(ans, dp[i][mid]+pd[i+1][k-i]/(ld)(mid+1));
	}
	}
	ans = min(ans, pd[1][k]);
	return ans;
}

int main () {
	ios_base::sync_with_stdio(false), cin.tie(0);
	cout<<fixed<<setprecision(10);

	cin>>n>>k;
	for(int i=1; i<=n; i++) {
		cin>>A[i]>>B[i];
		if(B[i]==-1) B[i] = 1000000;
		x[i] = {B[i], A[i]};
	}

	sort(x+1, x+n+1);

	for(int i=1; i<=n+1; i++) fill(pd[i], pd[i]+k+2, 1e9);
	pd[n+1][0] = 0;
	for(int i=n; i>=1; i--) {
		for(int j=0; j<=k; j++) {
			pd[i][j] = pd[i+1][j];
			if(j > 0) pd[i][j] = min(pd[i][j], pd[i+1][j-1] + x[i].S);
		}
	}

	ld res = 1e9;
	/*
	int l=0, r=k;
	while(r-l>1) {
		int mid = (l+r)/2;
		if(check(mid) > check(mid+1)) {
			res=min(res, check(mid+1));
			l=mid;
		} else {
			res=min(res, check(mid));
			r=mid;
		}
	}
	*/
	for(int i=0; i<=k; i++) res = min(res, check(i));

	cout<<res;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10584 KB Output is correct
4 Correct 2 ms 10704 KB Output is correct
5 Correct 21 ms 12632 KB Output is correct
6 Correct 105 ms 12752 KB Output is correct
7 Correct 410 ms 12756 KB Output is correct
8 Correct 729 ms 12756 KB Output is correct
9 Correct 1150 ms 12752 KB Output is correct
10 Correct 676 ms 12880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10584 KB Output is correct
4 Correct 2 ms 10704 KB Output is correct
5 Correct 21 ms 12632 KB Output is correct
6 Correct 105 ms 12752 KB Output is correct
7 Correct 410 ms 12756 KB Output is correct
8 Correct 729 ms 12756 KB Output is correct
9 Correct 1150 ms 12752 KB Output is correct
10 Correct 676 ms 12880 KB Output is correct
11 Correct 2 ms 10584 KB Output is correct
12 Correct 146 ms 12636 KB Output is correct
13 Correct 155 ms 12760 KB Output is correct
14 Correct 147 ms 12764 KB Output is correct
15 Correct 659 ms 12884 KB Output is correct
16 Correct 669 ms 12760 KB Output is correct
17 Correct 678 ms 12760 KB Output is correct
18 Correct 1145 ms 12772 KB Output is correct
19 Correct 1157 ms 12760 KB Output is correct
20 Correct 1135 ms 12756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10708 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 10584 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10584 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10704 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10708 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 10584 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10584 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10704 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 2 ms 10596 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 2 ms 10584 KB Output is correct
25 Correct 2 ms 10584 KB Output is correct
26 Correct 2 ms 10584 KB Output is correct
27 Correct 2 ms 10704 KB Output is correct
28 Correct 2 ms 10588 KB Output is correct
29 Correct 2 ms 10584 KB Output is correct
30 Correct 2 ms 10588 KB Output is correct
31 Correct 2 ms 10840 KB Output is correct
32 Correct 2 ms 10704 KB Output is correct
33 Correct 2 ms 10588 KB Output is correct
34 Correct 2 ms 10588 KB Output is correct
35 Correct 3 ms 10588 KB Output is correct
36 Correct 2 ms 10588 KB Output is correct
37 Correct 2 ms 10588 KB Output is correct
38 Correct 2 ms 10588 KB Output is correct
39 Correct 2 ms 10700 KB Output is correct
40 Correct 2 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10708 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 10584 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10584 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10704 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 2 ms 10596 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 2 ms 10584 KB Output is correct
25 Correct 2 ms 10584 KB Output is correct
26 Correct 2 ms 10584 KB Output is correct
27 Correct 2 ms 10704 KB Output is correct
28 Correct 2 ms 10588 KB Output is correct
29 Correct 2 ms 10584 KB Output is correct
30 Correct 2 ms 10588 KB Output is correct
31 Correct 2 ms 10840 KB Output is correct
32 Correct 2 ms 10704 KB Output is correct
33 Correct 2 ms 10588 KB Output is correct
34 Correct 2 ms 10588 KB Output is correct
35 Correct 3 ms 10588 KB Output is correct
36 Correct 2 ms 10588 KB Output is correct
37 Correct 2 ms 10588 KB Output is correct
38 Correct 2 ms 10588 KB Output is correct
39 Correct 2 ms 10700 KB Output is correct
40 Correct 2 ms 10588 KB Output is correct
41 Correct 2 ms 10588 KB Output is correct
42 Correct 3 ms 10596 KB Output is correct
43 Correct 3 ms 10588 KB Output is correct
44 Correct 3 ms 10588 KB Output is correct
45 Correct 5 ms 10588 KB Output is correct
46 Correct 5 ms 10720 KB Output is correct
47 Correct 6 ms 10588 KB Output is correct
48 Correct 7 ms 10588 KB Output is correct
49 Correct 9 ms 10588 KB Output is correct
50 Correct 8 ms 10584 KB Output is correct
51 Correct 12 ms 10584 KB Output is correct
52 Correct 11 ms 10724 KB Output is correct
53 Correct 7 ms 10728 KB Output is correct
54 Correct 6 ms 10588 KB Output is correct
55 Correct 7 ms 10584 KB Output is correct
56 Correct 7 ms 10584 KB Output is correct
57 Correct 7 ms 10588 KB Output is correct
58 Correct 7 ms 10704 KB Output is correct
59 Correct 6 ms 10728 KB Output is correct
60 Correct 9 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1149 ms 12880 KB Output is correct
2 Correct 1134 ms 12636 KB Output is correct
3 Correct 1130 ms 12832 KB Output is correct
4 Correct 1140 ms 12748 KB Output is correct
5 Correct 1145 ms 12748 KB Output is correct
6 Correct 1169 ms 12888 KB Output is correct
7 Correct 1130 ms 12752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10584 KB Output is correct
4 Correct 2 ms 10704 KB Output is correct
5 Correct 21 ms 12632 KB Output is correct
6 Correct 105 ms 12752 KB Output is correct
7 Correct 410 ms 12756 KB Output is correct
8 Correct 729 ms 12756 KB Output is correct
9 Correct 1150 ms 12752 KB Output is correct
10 Correct 676 ms 12880 KB Output is correct
11 Correct 2 ms 10584 KB Output is correct
12 Correct 146 ms 12636 KB Output is correct
13 Correct 155 ms 12760 KB Output is correct
14 Correct 147 ms 12764 KB Output is correct
15 Correct 659 ms 12884 KB Output is correct
16 Correct 669 ms 12760 KB Output is correct
17 Correct 678 ms 12760 KB Output is correct
18 Correct 1145 ms 12772 KB Output is correct
19 Correct 1157 ms 12760 KB Output is correct
20 Correct 1135 ms 12756 KB Output is correct
21 Correct 2 ms 10584 KB Output is correct
22 Correct 2 ms 10588 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 2 ms 10708 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 2 ms 10584 KB Output is correct
27 Correct 2 ms 10588 KB Output is correct
28 Correct 2 ms 10584 KB Output is correct
29 Correct 2 ms 10588 KB Output is correct
30 Correct 2 ms 10588 KB Output is correct
31 Correct 2 ms 10588 KB Output is correct
32 Correct 2 ms 10588 KB Output is correct
33 Correct 2 ms 10588 KB Output is correct
34 Correct 2 ms 10704 KB Output is correct
35 Correct 2 ms 10588 KB Output is correct
36 Correct 2 ms 10588 KB Output is correct
37 Correct 2 ms 10588 KB Output is correct
38 Correct 2 ms 10588 KB Output is correct
39 Correct 2 ms 10588 KB Output is correct
40 Correct 2 ms 10588 KB Output is correct
41 Correct 2 ms 10588 KB Output is correct
42 Correct 2 ms 10596 KB Output is correct
43 Correct 2 ms 10588 KB Output is correct
44 Correct 2 ms 10584 KB Output is correct
45 Correct 2 ms 10584 KB Output is correct
46 Correct 2 ms 10584 KB Output is correct
47 Correct 2 ms 10704 KB Output is correct
48 Correct 2 ms 10588 KB Output is correct
49 Correct 2 ms 10584 KB Output is correct
50 Correct 2 ms 10588 KB Output is correct
51 Correct 2 ms 10840 KB Output is correct
52 Correct 2 ms 10704 KB Output is correct
53 Correct 2 ms 10588 KB Output is correct
54 Correct 2 ms 10588 KB Output is correct
55 Correct 3 ms 10588 KB Output is correct
56 Correct 2 ms 10588 KB Output is correct
57 Correct 2 ms 10588 KB Output is correct
58 Correct 2 ms 10588 KB Output is correct
59 Correct 2 ms 10700 KB Output is correct
60 Correct 2 ms 10588 KB Output is correct
61 Correct 2 ms 10588 KB Output is correct
62 Correct 3 ms 10596 KB Output is correct
63 Correct 3 ms 10588 KB Output is correct
64 Correct 3 ms 10588 KB Output is correct
65 Correct 5 ms 10588 KB Output is correct
66 Correct 5 ms 10720 KB Output is correct
67 Correct 6 ms 10588 KB Output is correct
68 Correct 7 ms 10588 KB Output is correct
69 Correct 9 ms 10588 KB Output is correct
70 Correct 8 ms 10584 KB Output is correct
71 Correct 12 ms 10584 KB Output is correct
72 Correct 11 ms 10724 KB Output is correct
73 Correct 7 ms 10728 KB Output is correct
74 Correct 6 ms 10588 KB Output is correct
75 Correct 7 ms 10584 KB Output is correct
76 Correct 7 ms 10584 KB Output is correct
77 Correct 7 ms 10588 KB Output is correct
78 Correct 7 ms 10704 KB Output is correct
79 Correct 6 ms 10728 KB Output is correct
80 Correct 9 ms 10588 KB Output is correct
81 Correct 1149 ms 12880 KB Output is correct
82 Correct 1134 ms 12636 KB Output is correct
83 Correct 1130 ms 12832 KB Output is correct
84 Correct 1140 ms 12748 KB Output is correct
85 Correct 1145 ms 12748 KB Output is correct
86 Correct 1169 ms 12888 KB Output is correct
87 Correct 1130 ms 12752 KB Output is correct
88 Correct 23 ms 12756 KB Output is correct
89 Correct 24 ms 12780 KB Output is correct
90 Correct 104 ms 12760 KB Output is correct
91 Correct 104 ms 12636 KB Output is correct
92 Correct 371 ms 12756 KB Output is correct
93 Correct 365 ms 12888 KB Output is correct
94 Correct 739 ms 12756 KB Output is correct
95 Correct 731 ms 12760 KB Output is correct
96 Correct 997 ms 12888 KB Output is correct
97 Correct 1033 ms 12752 KB Output is correct
98 Correct 664 ms 12752 KB Output is correct
99 Correct 684 ms 12756 KB Output is correct
100 Correct 646 ms 12884 KB Output is correct
101 Correct 649 ms 12756 KB Output is correct
102 Correct 658 ms 12632 KB Output is correct
103 Correct 671 ms 12756 KB Output is correct
104 Correct 676 ms 12772 KB Output is correct
105 Correct 676 ms 12752 KB Output is correct