답안 #1019238

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1019238 2024-07-10T16:04:40 Z Nurislam Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
1881 ms 4444 KB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>  
#define int long long
#define double long double
const int N = 1e6+5, inf = 1e9, mod = 1e9+7;
template <class F, class _S>
bool chmin(F &u, const _S &v){
	bool flag = false;
	if ( u > v ){
		u = v; flag |= true;
	}
	return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
	bool flag = false;
	if ( u < v ){
		u = v; flag |= true;
	}
	return flag;
}
double dp[505][505];
void solve(){
	int n, k;cin >> n >> k;
	vector<pair<int,int> > v;
	for(int i = 0; i < n; i++){
		int a, b;
		cin >> a >> b;
		if(b == -1)b = inf;
		v.pb({b, a});
	}
	sort(all(v));
	vector<int> a(n+1), b(n+1);
	for(int i = 1; i <= n; i++){
		b[i] = v[i-1].ff;
		a[i] = v[i-1].ss;
	}
	vector<int> _a;
	for(int i = 1; i <= n; i++)_a.pb(a[i]);
	sort(all(_a));
	double ans = 0;
	for(int i = 0; i < k; i++)ans+=_a[i];
	for(int m = 1; m <= k; m++){
		for(int i = 0; i <= n; i++)
			for(int j = 0; j <= n; j++)dp[i][j] = inf;
		dp[0][0] = 0;
		for(int i = 1; i <= k; i++){
			for(int j = 0; j <= min(i, m); j++){
				if(j && b[i] < inf)chmin(dp[i][j], dp[i-1][j-1] + (double)b[i]/(double)(j));
				chmin(dp[i][j], dp[i-1][j] + (double)a[i]/(double)(m+1));
				if(j==m){
                    vector<int> v;
                    for(int q = i+1;q <= n; q++)v.pb(a[q]);
                    sort(all(v));
 
                    int sum = 0;
                    for(int q = 0; q < k-i; q++)sum += v[q];
                    chmin(ans, dp[i][j] + (double)sum / (double)(m+1));
                }
			}
		}
	}
	cout << fixed << setprecision(15) << ans << '\n';
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int tt = 1;
	//cin >> tt;
	while(tt--){
		solve();
	}
}
 
 
 
 
 
 
 
 
 
 
 
 
 
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 508 KB Output is correct
5 Correct 76 ms 4440 KB Output is correct
6 Correct 235 ms 4440 KB Output is correct
7 Correct 536 ms 4440 KB Output is correct
8 Correct 812 ms 4440 KB Output is correct
9 Correct 1192 ms 4440 KB Output is correct
10 Correct 704 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 508 KB Output is correct
5 Correct 76 ms 4440 KB Output is correct
6 Correct 235 ms 4440 KB Output is correct
7 Correct 536 ms 4440 KB Output is correct
8 Correct 812 ms 4440 KB Output is correct
9 Correct 1192 ms 4440 KB Output is correct
10 Correct 704 ms 4444 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 260 ms 4424 KB Output is correct
13 Correct 297 ms 4444 KB Output is correct
14 Correct 283 ms 4444 KB Output is correct
15 Correct 811 ms 4444 KB Output is correct
16 Correct 961 ms 4444 KB Output is correct
17 Correct 779 ms 4444 KB Output is correct
18 Correct 1457 ms 4444 KB Output is correct
19 Correct 1404 ms 4444 KB Output is correct
20 Correct 1201 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 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 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 464 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 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 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 464 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 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 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 464 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 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 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 464 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 2 ms 2392 KB Output is correct
42 Correct 2 ms 972 KB Output is correct
43 Correct 4 ms 2508 KB Output is correct
44 Correct 3 ms 2396 KB Output is correct
45 Correct 6 ms 900 KB Output is correct
46 Correct 6 ms 2396 KB Output is correct
47 Correct 7 ms 2396 KB Output is correct
48 Correct 8 ms 2652 KB Output is correct
49 Correct 9 ms 856 KB Output is correct
50 Correct 11 ms 2396 KB Output is correct
51 Correct 12 ms 1040 KB Output is correct
52 Correct 16 ms 2396 KB Output is correct
53 Correct 7 ms 2396 KB Output is correct
54 Correct 7 ms 2392 KB Output is correct
55 Correct 9 ms 2396 KB Output is correct
56 Correct 7 ms 860 KB Output is correct
57 Correct 8 ms 2644 KB Output is correct
58 Correct 6 ms 860 KB Output is correct
59 Correct 7 ms 2648 KB Output is correct
60 Correct 7 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1880 ms 4440 KB Output is correct
2 Correct 1728 ms 4444 KB Output is correct
3 Correct 1876 ms 4252 KB Output is correct
4 Correct 1881 ms 4444 KB Output is correct
5 Correct 1848 ms 4444 KB Output is correct
6 Correct 1855 ms 4444 KB Output is correct
7 Correct 1716 ms 4424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 508 KB Output is correct
5 Correct 76 ms 4440 KB Output is correct
6 Correct 235 ms 4440 KB Output is correct
7 Correct 536 ms 4440 KB Output is correct
8 Correct 812 ms 4440 KB Output is correct
9 Correct 1192 ms 4440 KB Output is correct
10 Correct 704 ms 4444 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 260 ms 4424 KB Output is correct
13 Correct 297 ms 4444 KB Output is correct
14 Correct 283 ms 4444 KB Output is correct
15 Correct 811 ms 4444 KB Output is correct
16 Correct 961 ms 4444 KB Output is correct
17 Correct 779 ms 4444 KB Output is correct
18 Correct 1457 ms 4444 KB Output is correct
19 Correct 1404 ms 4444 KB Output is correct
20 Correct 1201 ms 4432 KB Output is correct
21 Correct 0 ms 344 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 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 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 1 ms 348 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 1 ms 464 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 464 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 2 ms 2392 KB Output is correct
62 Correct 2 ms 972 KB Output is correct
63 Correct 4 ms 2508 KB Output is correct
64 Correct 3 ms 2396 KB Output is correct
65 Correct 6 ms 900 KB Output is correct
66 Correct 6 ms 2396 KB Output is correct
67 Correct 7 ms 2396 KB Output is correct
68 Correct 8 ms 2652 KB Output is correct
69 Correct 9 ms 856 KB Output is correct
70 Correct 11 ms 2396 KB Output is correct
71 Correct 12 ms 1040 KB Output is correct
72 Correct 16 ms 2396 KB Output is correct
73 Correct 7 ms 2396 KB Output is correct
74 Correct 7 ms 2392 KB Output is correct
75 Correct 9 ms 2396 KB Output is correct
76 Correct 7 ms 860 KB Output is correct
77 Correct 8 ms 2644 KB Output is correct
78 Correct 6 ms 860 KB Output is correct
79 Correct 7 ms 2648 KB Output is correct
80 Correct 7 ms 2644 KB Output is correct
81 Correct 1880 ms 4440 KB Output is correct
82 Correct 1728 ms 4444 KB Output is correct
83 Correct 1876 ms 4252 KB Output is correct
84 Correct 1881 ms 4444 KB Output is correct
85 Correct 1848 ms 4444 KB Output is correct
86 Correct 1855 ms 4444 KB Output is correct
87 Correct 1716 ms 4424 KB Output is correct
88 Correct 89 ms 4444 KB Output is correct
89 Correct 96 ms 4444 KB Output is correct
90 Correct 291 ms 4440 KB Output is correct
91 Correct 282 ms 4444 KB Output is correct
92 Correct 714 ms 4444 KB Output is correct
93 Correct 770 ms 4444 KB Output is correct
94 Correct 1336 ms 4444 KB Output is correct
95 Correct 1269 ms 4432 KB Output is correct
96 Correct 1587 ms 4432 KB Output is correct
97 Correct 1653 ms 4444 KB Output is correct
98 Correct 1148 ms 4444 KB Output is correct
99 Correct 1164 ms 4440 KB Output is correct
100 Correct 1201 ms 4444 KB Output is correct
101 Correct 1138 ms 4440 KB Output is correct
102 Correct 1029 ms 4444 KB Output is correct
103 Correct 987 ms 4440 KB Output is correct
104 Correct 953 ms 4440 KB Output is correct
105 Correct 787 ms 4444 KB Output is correct