답안 #529579

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
529579 2022-02-23T08:20:15 Z fhvirus Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
2050 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

const ll MUL = 1e9;
const ll INF = 1e18;
const int kN = 505;
int N, K;
pii state[kN];
ll 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];
	ll 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] + state[i].ff * MUL / (g + 1));
						if (j > 0 and k > 0)
							dp[j][k] = min(dp[j][k], sc[j - 1][k - 1] + state[i].ss * MUL / k);
						debug(i, j, k, dp[j][k]);
					}
				else {
					dp[j][g] = sc[j][g];
					if (j > 0)
						dp[j][g] = min(dp[j][g], sc[j - 1][g] + state[i].ff * MUL / (g + 1));
					if (j > 0 and g > 0)
						dp[j][g] = min(dp[j][g], sc[j - 1][g - 1] + state[i].ss * MUL / g);
				}
			swap(dp, sc);
		}
		ans = min(ans, sc[K][g]);
	}

	cout << setprecision(9) << fixed << ((double) ans / MUL) << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 332 KB Output is correct
5 Correct 29 ms 724 KB Output is correct
6 Correct 160 ms 1304 KB Output is correct
7 Correct 594 ms 2292 KB Output is correct
8 Correct 1243 ms 3276 KB Output is correct
9 Correct 2050 ms 4384 KB Output is correct
10 Correct 1110 ms 3084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 332 KB Output is correct
5 Correct 29 ms 724 KB Output is correct
6 Correct 160 ms 1304 KB Output is correct
7 Correct 594 ms 2292 KB Output is correct
8 Correct 1243 ms 3276 KB Output is correct
9 Correct 2050 ms 4384 KB Output is correct
10 Correct 1110 ms 3084 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 209 ms 1496 KB Output is correct
13 Correct 215 ms 1484 KB Output is correct
14 Correct 230 ms 1496 KB Output is correct
15 Correct 996 ms 3080 KB Output is correct
16 Correct 1037 ms 3084 KB Output is correct
17 Correct 1089 ms 3208 KB Output is correct
18 Correct 1874 ms 4272 KB Output is correct
19 Correct 1950 ms 4260 KB Output is correct
20 Correct 2021 ms 4264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 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 1 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 1 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 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 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 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 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 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 1 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 1 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 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 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 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 2 ms 460 KB Output is correct
44 Correct 2 ms 460 KB Output is correct
45 Correct 5 ms 844 KB Output is correct
46 Correct 6 ms 724 KB Output is correct
47 Correct 8 ms 840 KB Output is correct
48 Correct 8 ms 716 KB Output is correct
49 Correct 11 ms 960 KB Output is correct
50 Correct 11 ms 844 KB Output is correct
51 Correct 17 ms 1120 KB Output is correct
52 Correct 18 ms 1100 KB Output is correct
53 Correct 8 ms 716 KB Output is correct
54 Correct 8 ms 716 KB Output is correct
55 Correct 8 ms 844 KB Output is correct
56 Correct 8 ms 844 KB Output is correct
57 Correct 8 ms 716 KB Output is correct
58 Correct 8 ms 716 KB Output is correct
59 Correct 9 ms 716 KB Output is correct
60 Correct 8 ms 840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1861 ms 4384 KB Output is correct
2 Correct 1845 ms 4252 KB Output is correct
3 Correct 1864 ms 4272 KB Output is correct
4 Correct 1865 ms 4256 KB Output is correct
5 Correct 1860 ms 4172 KB Output is correct
6 Correct 1863 ms 4256 KB Output is correct
7 Correct 1860 ms 4256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 332 KB Output is correct
5 Correct 29 ms 724 KB Output is correct
6 Correct 160 ms 1304 KB Output is correct
7 Correct 594 ms 2292 KB Output is correct
8 Correct 1243 ms 3276 KB Output is correct
9 Correct 2050 ms 4384 KB Output is correct
10 Correct 1110 ms 3084 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 209 ms 1496 KB Output is correct
13 Correct 215 ms 1484 KB Output is correct
14 Correct 230 ms 1496 KB Output is correct
15 Correct 996 ms 3080 KB Output is correct
16 Correct 1037 ms 3084 KB Output is correct
17 Correct 1089 ms 3208 KB Output is correct
18 Correct 1874 ms 4272 KB Output is correct
19 Correct 1950 ms 4260 KB Output is correct
20 Correct 2021 ms 4264 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 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 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 0 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 0 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 1 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 1 ms 460 KB Output is correct
46 Correct 1 ms 460 KB Output is correct
47 Correct 1 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 1 ms 332 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 1 ms 332 KB Output is correct
54 Correct 1 ms 332 KB Output is correct
55 Correct 1 ms 332 KB Output is correct
56 Correct 1 ms 332 KB Output is correct
57 Correct 1 ms 332 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 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 2 ms 460 KB Output is correct
64 Correct 2 ms 460 KB Output is correct
65 Correct 5 ms 844 KB Output is correct
66 Correct 6 ms 724 KB Output is correct
67 Correct 8 ms 840 KB Output is correct
68 Correct 8 ms 716 KB Output is correct
69 Correct 11 ms 960 KB Output is correct
70 Correct 11 ms 844 KB Output is correct
71 Correct 17 ms 1120 KB Output is correct
72 Correct 18 ms 1100 KB Output is correct
73 Correct 8 ms 716 KB Output is correct
74 Correct 8 ms 716 KB Output is correct
75 Correct 8 ms 844 KB Output is correct
76 Correct 8 ms 844 KB Output is correct
77 Correct 8 ms 716 KB Output is correct
78 Correct 8 ms 716 KB Output is correct
79 Correct 9 ms 716 KB Output is correct
80 Correct 8 ms 840 KB Output is correct
81 Correct 1861 ms 4384 KB Output is correct
82 Correct 1845 ms 4252 KB Output is correct
83 Correct 1864 ms 4272 KB Output is correct
84 Correct 1865 ms 4256 KB Output is correct
85 Correct 1860 ms 4172 KB Output is correct
86 Correct 1863 ms 4256 KB Output is correct
87 Correct 1860 ms 4256 KB Output is correct
88 Correct 26 ms 716 KB Output is correct
89 Correct 26 ms 716 KB Output is correct
90 Correct 147 ms 1228 KB Output is correct
91 Correct 149 ms 1308 KB Output is correct
92 Correct 537 ms 2284 KB Output is correct
93 Correct 545 ms 2252 KB Output is correct
94 Correct 1119 ms 3276 KB Output is correct
95 Correct 1137 ms 3276 KB Output is correct
96 Correct 1529 ms 3868 KB Output is correct
97 Correct 1558 ms 3868 KB Output is correct
98 Correct 983 ms 3140 KB Output is correct
99 Correct 983 ms 3144 KB Output is correct
100 Correct 992 ms 3148 KB Output is correct
101 Correct 1002 ms 3080 KB Output is correct
102 Correct 1004 ms 3092 KB Output is correct
103 Correct 1002 ms 3144 KB Output is correct
104 Correct 988 ms 3068 KB Output is correct
105 Correct 956 ms 3080 KB Output is correct