답안 #529582

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
529582 2022-02-23T08:25:18 Z fhvirus Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
799 ms 4384 KB
// Knapsack DP is harder than FFT.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb emplace_back
#define AI(x) begin(x),end(x)
#ifdef OWO
#define debug(args...) SDF(#args, args)
#define OIU(args...) ostream& operator<<(ostream&O,args)
#define LKJ(S,B,E,F) template<class...T>OIU(S<T...>s){O<<B;int c=0;for(auto i:s)O<<(c++?", ":"")<<F;return O<<E;}
LKJ(vector,'[',']',i)LKJ(deque,'[',']',i)LKJ(set,'{','}',i)LKJ(multiset,'{','}',i)LKJ(unordered_set,'{','}',i)LKJ(map,'{','}',i.ff<<':'<<i.ss)LKJ(unordered_map,'{','}',i.ff<<':'<<i.ss)
template<class...T>void SDF(const char* s,T...a){int c=sizeof...(T);if(!c){cerr<<"\033[1;32mvoid\033[0m\n";return;}(cerr<<"\033[1;32m("<<s<<") = (",...,(cerr<<a<<(--c?", ":")\033[0m\n")));}
template<class T,size_t N>OIU(array<T,N>a){return O<<vector<T>(AI(a));}template<class...T>OIU(pair<T...>p){return O<<'('<<p.ff<<','<<p.ss<<')';}template<class...T>OIU(tuple<T...>t){return O<<'(',apply([&O](T...s){int c=0;(...,(O<<(c++?", ":"")<<s));},t),O<<')';}
#else
#define debug(...) ((void)0)
#endif

#pragma GCC optimize("Ofast")

const double INF = 1e18;
const int kN = 505;
int N, K;
pii state[kN];
double pool[2][kN][kN];

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> N >> K;
	for (int i = 1; i <= N; ++i) {
		cin >> state[i].ff >> state[i].ss;
		if (state[i].ss == -1)
			state[i].ss = 1'000'000;
	}

	sort(state + 1, state + N + 1, [](const pii &a, const pii &b) {
		if (a.ss != b.ss) return a.ss < b.ss;
		return a.ff > b.ff;
	});

	auto dp = pool[0], sc = pool[1];
	double ans = INF;
	for (int g = 0; g <= K; ++g) {
		for (int j = 0; j <= K; ++j)
			for (int k = 0; k <= g; ++k)
				dp[j][k] = sc[j][k] = INF;
		sc[0][0] = 0;
		for (int i = 1; i <= N; ++i) {
			for (int j = 0; j <= i and j <= K; ++j)
				if (i == j)
					for (int k = 0; k <= g; ++k) {
						dp[j][k] = sc[j][k];
						if (j > 0)
							dp[j][k] = min(dp[j][k], sc[j - 1][k] + (double) state[i].ff / (g + 1));
						if (j > 0 and k > 0)
							dp[j][k] = min(dp[j][k], sc[j - 1][k - 1] + (double) state[i].ss / k);
					}
				else {
					dp[j][g] = sc[j][g];
					if (j > 0)
						dp[j][g] = min(dp[j][g], sc[j - 1][g] + (double) state[i].ff / (g + 1));
					if (j > 0 and g > 0)
						dp[j][g] = min(dp[j][g], sc[j - 1][g - 1] + (double) state[i].ss / g);
				}
			swap(dp, sc);
		}
		ans = min(ans, sc[K][g]);
	}

	cout << setprecision(9) << fixed << ans << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 9 ms 716 KB Output is correct
6 Correct 51 ms 1228 KB Output is correct
7 Correct 198 ms 2304 KB Output is correct
8 Correct 445 ms 3284 KB Output is correct
9 Correct 776 ms 4384 KB Output is correct
10 Correct 377 ms 3072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 9 ms 716 KB Output is correct
6 Correct 51 ms 1228 KB Output is correct
7 Correct 198 ms 2304 KB Output is correct
8 Correct 445 ms 3284 KB Output is correct
9 Correct 776 ms 4384 KB Output is correct
10 Correct 377 ms 3072 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 75 ms 1496 KB Output is correct
13 Correct 73 ms 1500 KB Output is correct
14 Correct 75 ms 1484 KB Output is correct
15 Correct 379 ms 3076 KB Output is correct
16 Correct 396 ms 3084 KB Output is correct
17 Correct 379 ms 3072 KB Output is correct
18 Correct 764 ms 4252 KB Output is correct
19 Correct 781 ms 4256 KB Output is correct
20 Correct 765 ms 4260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 460 KB Output is correct
26 Correct 0 ms 460 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 0 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 0 ms 336 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 0 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 460 KB Output is correct
26 Correct 0 ms 460 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 0 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 0 ms 336 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 0 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 460 KB Output is correct
44 Correct 1 ms 460 KB Output is correct
45 Correct 2 ms 716 KB Output is correct
46 Correct 2 ms 716 KB Output is correct
47 Correct 3 ms 716 KB Output is correct
48 Correct 5 ms 844 KB Output is correct
49 Correct 5 ms 844 KB Output is correct
50 Correct 5 ms 844 KB Output is correct
51 Correct 6 ms 1100 KB Output is correct
52 Correct 8 ms 1120 KB Output is correct
53 Correct 3 ms 716 KB Output is correct
54 Correct 4 ms 844 KB Output is correct
55 Correct 4 ms 716 KB Output is correct
56 Correct 3 ms 716 KB Output is correct
57 Correct 3 ms 716 KB Output is correct
58 Correct 3 ms 716 KB Output is correct
59 Correct 4 ms 844 KB Output is correct
60 Correct 3 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 799 ms 4380 KB Output is correct
2 Correct 778 ms 4260 KB Output is correct
3 Correct 788 ms 4260 KB Output is correct
4 Correct 763 ms 4376 KB Output is correct
5 Correct 765 ms 4260 KB Output is correct
6 Correct 765 ms 4292 KB Output is correct
7 Correct 762 ms 4268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 9 ms 716 KB Output is correct
6 Correct 51 ms 1228 KB Output is correct
7 Correct 198 ms 2304 KB Output is correct
8 Correct 445 ms 3284 KB Output is correct
9 Correct 776 ms 4384 KB Output is correct
10 Correct 377 ms 3072 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 75 ms 1496 KB Output is correct
13 Correct 73 ms 1500 KB Output is correct
14 Correct 75 ms 1484 KB Output is correct
15 Correct 379 ms 3076 KB Output is correct
16 Correct 396 ms 3084 KB Output is correct
17 Correct 379 ms 3072 KB Output is correct
18 Correct 764 ms 4252 KB Output is correct
19 Correct 781 ms 4256 KB Output is correct
20 Correct 765 ms 4260 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 0 ms 332 KB Output is correct
33 Correct 0 ms 332 KB Output is correct
34 Correct 0 ms 332 KB Output is correct
35 Correct 0 ms 332 KB Output is correct
36 Correct 0 ms 332 KB Output is correct
37 Correct 0 ms 332 KB Output is correct
38 Correct 0 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 0 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 0 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 0 ms 460 KB Output is correct
46 Correct 0 ms 460 KB Output is correct
47 Correct 0 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 0 ms 332 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 1 ms 336 KB Output is correct
53 Correct 0 ms 336 KB Output is correct
54 Correct 1 ms 336 KB Output is correct
55 Correct 0 ms 336 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 0 ms 332 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 1 ms 332 KB Output is correct
62 Correct 1 ms 332 KB Output is correct
63 Correct 1 ms 460 KB Output is correct
64 Correct 1 ms 460 KB Output is correct
65 Correct 2 ms 716 KB Output is correct
66 Correct 2 ms 716 KB Output is correct
67 Correct 3 ms 716 KB Output is correct
68 Correct 5 ms 844 KB Output is correct
69 Correct 5 ms 844 KB Output is correct
70 Correct 5 ms 844 KB Output is correct
71 Correct 6 ms 1100 KB Output is correct
72 Correct 8 ms 1120 KB Output is correct
73 Correct 3 ms 716 KB Output is correct
74 Correct 4 ms 844 KB Output is correct
75 Correct 4 ms 716 KB Output is correct
76 Correct 3 ms 716 KB Output is correct
77 Correct 3 ms 716 KB Output is correct
78 Correct 3 ms 716 KB Output is correct
79 Correct 4 ms 844 KB Output is correct
80 Correct 3 ms 716 KB Output is correct
81 Correct 799 ms 4380 KB Output is correct
82 Correct 778 ms 4260 KB Output is correct
83 Correct 788 ms 4260 KB Output is correct
84 Correct 763 ms 4376 KB Output is correct
85 Correct 765 ms 4260 KB Output is correct
86 Correct 765 ms 4292 KB Output is correct
87 Correct 762 ms 4268 KB Output is correct
88 Correct 9 ms 716 KB Output is correct
89 Correct 9 ms 716 KB Output is correct
90 Correct 52 ms 1228 KB Output is correct
91 Correct 62 ms 1296 KB Output is correct
92 Correct 198 ms 2284 KB Output is correct
93 Correct 202 ms 2284 KB Output is correct
94 Correct 435 ms 3276 KB Output is correct
95 Correct 443 ms 3276 KB Output is correct
96 Correct 631 ms 3788 KB Output is correct
97 Correct 634 ms 3788 KB Output is correct
98 Correct 383 ms 3076 KB Output is correct
99 Correct 398 ms 3088 KB Output is correct
100 Correct 379 ms 3020 KB Output is correct
101 Correct 398 ms 3076 KB Output is correct
102 Correct 382 ms 3088 KB Output is correct
103 Correct 388 ms 3072 KB Output is correct
104 Correct 380 ms 3020 KB Output is correct
105 Correct 387 ms 3080 KB Output is correct