Submission #936907

# Submission time Handle Problem Language Result Execution time Memory
936907 2024-03-03T02:13:14 Z william950615 Let's Win the Election (JOI22_ho_t3) C++14
100 / 100
2470 ms 1628 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define mkp make_pair
#define PH push
#define PB push_back
#define REP(i,N) for( int i = 0; i < (N); ++i )
#define FOR(i,a,b) for( int i = (a); i <= (b); ++i )
#define ALL(x) begin(x), end(x)
#define MEM(x) memset(x, 0, sizeof(x))

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T>
using V=vector<T>;
#define double float

void solve() {
	int N, K; cin >> N >> K;
	V<pll> vc(N+1, mkp(0,0));
	const ll INF = 1e18;
	FOR(i,1,N) cin >> vc[i].F >> vc[i].S;
	int cnt = 0;
	for( auto &i : vc ) if( i.S == -1 ) i.S = INF,++cnt;
	cnt = N-cnt+1;
	cnt = min( K, cnt );

	sort( vc.begin()+1, vc.end(), [&]( auto&a, auto&b) {
			return a.S < b.S;
		});
	
	//V<V<V<double>>> dp( 2, V<V<double>>( K+1, V<double>(K+1, 0) ));
	V<V<double>> dp(K+1,V<double>(K+1,0));
	//double dp[ N+1 ][ K+1 ][ K+1 ];

	auto init = [&]() {
		for( auto &i : dp ) for( auto &j : i )/* for( auto &k : j ) */
			j = INF;
		dp[ 1 ][ 0 ] = 0;
	};

	auto do_dp = [&](int p) {
		double ans=INF;
		init();
		for( int i = 1; i <= N; ++i ) {
			double val = 1.0f*vc[i].F/p;
			for( int j = p; j>=1; --j ) {
				double val2 = ( j ==1 ? INF :1.0f*vc[i].S/(j-1) );
				for( int k = K; k >=1; --k ) {
					dp[ j ][ k ] = min({
						( j == 1 ? INF : dp[j-1][k-1]+val2 ), 
						dp[j][k-1] + val,
						dp[j][k]
					});
				}
			}
		}
		//fprintf(stderr, "ans:(%.16lf), p(%d)\n", ans, p );
		ans = min( dp[p][K], ans );
		return ans;
	};

	int l = 1, r = cnt;
	double ans = INF;
	while( r-l > 4 ) {
		int l1 = (l+l+r)/3, l2 = (l+r+r)/3;
		double ans1 = do_dp(l1);
		double ans2 = do_dp(l2);
		ans = min( {ans,ans1,ans2} );
		if( ans1 > ans2 ) 
			l=l1;
		else
			r=l2;
	}
	for( int i = l; i<=r; ++i ) 
		ans = min( ans, do_dp(i));

	cout << fixed << setprecision(10);
	cout << ans << '\n';
}

int main() {
	int T = 1;
#ifdef LOCAL
	freopen( "input.txt", "r", stdin);
	freopen( "output.txt", "w", stdout );
	cin >> T;
#else
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
	while(T--) solve();

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 1368 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 1368 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 217 ms 540 KB Output is correct
13 Correct 146 ms 532 KB Output is correct
14 Correct 91 ms 536 KB Output is correct
15 Correct 1181 ms 936 KB Output is correct
16 Correct 764 ms 1112 KB Output is correct
17 Correct 256 ms 860 KB Output is correct
18 Correct 2470 ms 1444 KB Output is correct
19 Correct 1272 ms 1440 KB Output is correct
20 Correct 362 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 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 344 KB Output is correct
27 Correct 0 ms 600 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 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 344 KB Output is correct
27 Correct 0 ms 600 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 4 ms 348 KB Output is correct
46 Correct 2 ms 348 KB Output is correct
47 Correct 4 ms 348 KB Output is correct
48 Correct 6 ms 348 KB Output is correct
49 Correct 9 ms 348 KB Output is correct
50 Correct 7 ms 348 KB Output is correct
51 Correct 12 ms 492 KB Output is correct
52 Correct 14 ms 348 KB Output is correct
53 Correct 3 ms 348 KB Output is correct
54 Correct 4 ms 348 KB Output is correct
55 Correct 7 ms 348 KB Output is correct
56 Correct 3 ms 348 KB Output is correct
57 Correct 6 ms 348 KB Output is correct
58 Correct 7 ms 348 KB Output is correct
59 Correct 7 ms 476 KB Output is correct
60 Correct 6 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1412 ms 1628 KB Output is correct
2 Correct 1535 ms 1620 KB Output is correct
3 Correct 1783 ms 1448 KB Output is correct
4 Correct 1965 ms 1444 KB Output is correct
5 Correct 2172 ms 1440 KB Output is correct
6 Correct 1186 ms 1440 KB Output is correct
7 Correct 2328 ms 1444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 1368 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 217 ms 540 KB Output is correct
13 Correct 146 ms 532 KB Output is correct
14 Correct 91 ms 536 KB Output is correct
15 Correct 1181 ms 936 KB Output is correct
16 Correct 764 ms 1112 KB Output is correct
17 Correct 256 ms 860 KB Output is correct
18 Correct 2470 ms 1444 KB Output is correct
19 Correct 1272 ms 1440 KB Output is correct
20 Correct 362 ms 1372 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 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 1 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 0 ms 600 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 344 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 1 ms 344 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 1 ms 344 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 4 ms 348 KB Output is correct
66 Correct 2 ms 348 KB Output is correct
67 Correct 4 ms 348 KB Output is correct
68 Correct 6 ms 348 KB Output is correct
69 Correct 9 ms 348 KB Output is correct
70 Correct 7 ms 348 KB Output is correct
71 Correct 12 ms 492 KB Output is correct
72 Correct 14 ms 348 KB Output is correct
73 Correct 3 ms 348 KB Output is correct
74 Correct 4 ms 348 KB Output is correct
75 Correct 7 ms 348 KB Output is correct
76 Correct 3 ms 348 KB Output is correct
77 Correct 6 ms 348 KB Output is correct
78 Correct 7 ms 348 KB Output is correct
79 Correct 7 ms 476 KB Output is correct
80 Correct 6 ms 348 KB Output is correct
81 Correct 1412 ms 1628 KB Output is correct
82 Correct 1535 ms 1620 KB Output is correct
83 Correct 1783 ms 1448 KB Output is correct
84 Correct 1965 ms 1444 KB Output is correct
85 Correct 2172 ms 1440 KB Output is correct
86 Correct 1186 ms 1440 KB Output is correct
87 Correct 2328 ms 1444 KB Output is correct
88 Correct 6 ms 600 KB Output is correct
89 Correct 20 ms 348 KB Output is correct
90 Correct 63 ms 516 KB Output is correct
91 Correct 126 ms 512 KB Output is correct
92 Correct 242 ms 852 KB Output is correct
93 Correct 441 ms 700 KB Output is correct
94 Correct 615 ms 1104 KB Output is correct
95 Correct 1020 ms 1012 KB Output is correct
96 Correct 1095 ms 1260 KB Output is correct
97 Correct 1635 ms 1260 KB Output is correct
98 Correct 358 ms 940 KB Output is correct
99 Correct 208 ms 860 KB Output is correct
100 Correct 537 ms 1112 KB Output is correct
101 Correct 741 ms 860 KB Output is correct
102 Correct 934 ms 940 KB Output is correct
103 Correct 941 ms 940 KB Output is correct
104 Correct 805 ms 956 KB Output is correct
105 Correct 122 ms 856 KB Output is correct