Submission #529581

# Submission time Handle Problem Language Result Execution time Memory
529581 2022-02-23T08:23:40 Z fhvirus Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
2105 ms 4388 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 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);
					}
				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;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 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 27 ms 728 KB Output is correct
6 Correct 171 ms 1292 KB Output is correct
7 Correct 601 ms 2284 KB Output is correct
8 Correct 1257 ms 3276 KB Output is correct
9 Correct 2105 ms 4384 KB Output is correct
10 Correct 1128 ms 3196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 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 27 ms 728 KB Output is correct
6 Correct 171 ms 1292 KB Output is correct
7 Correct 601 ms 2284 KB Output is correct
8 Correct 1257 ms 3276 KB Output is correct
9 Correct 2105 ms 4384 KB Output is correct
10 Correct 1128 ms 3196 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 213 ms 1492 KB Output is correct
13 Correct 224 ms 1500 KB Output is correct
14 Correct 226 ms 1496 KB Output is correct
15 Correct 1026 ms 3088 KB Output is correct
16 Correct 1047 ms 3080 KB Output is correct
17 Correct 1082 ms 3072 KB Output is correct
18 Correct 1861 ms 4260 KB Output is correct
19 Correct 1953 ms 4272 KB Output is correct
20 Correct 2027 ms 4296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 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 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 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 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 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 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 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 0 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 408 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 0 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 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 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 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 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 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 0 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 408 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 0 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 2 ms 460 KB Output is correct
44 Correct 2 ms 460 KB Output is correct
45 Correct 5 ms 716 KB Output is correct
46 Correct 5 ms 716 KB Output is correct
47 Correct 8 ms 716 KB Output is correct
48 Correct 9 ms 836 KB Output is correct
49 Correct 11 ms 956 KB Output is correct
50 Correct 11 ms 844 KB Output is correct
51 Correct 16 ms 1124 KB Output is correct
52 Correct 17 ms 1100 KB Output is correct
53 Correct 8 ms 716 KB Output is correct
54 Correct 8 ms 840 KB Output is correct
55 Correct 8 ms 840 KB Output is correct
56 Correct 8 ms 716 KB Output is correct
57 Correct 8 ms 716 KB Output is correct
58 Correct 8 ms 716 KB Output is correct
59 Correct 8 ms 716 KB Output is correct
60 Correct 9 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1838 ms 4264 KB Output is correct
2 Correct 1838 ms 4384 KB Output is correct
3 Correct 1855 ms 4272 KB Output is correct
4 Correct 1854 ms 4380 KB Output is correct
5 Correct 1850 ms 4380 KB Output is correct
6 Correct 1834 ms 4388 KB Output is correct
7 Correct 1839 ms 4292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 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 27 ms 728 KB Output is correct
6 Correct 171 ms 1292 KB Output is correct
7 Correct 601 ms 2284 KB Output is correct
8 Correct 1257 ms 3276 KB Output is correct
9 Correct 2105 ms 4384 KB Output is correct
10 Correct 1128 ms 3196 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 213 ms 1492 KB Output is correct
13 Correct 224 ms 1500 KB Output is correct
14 Correct 226 ms 1496 KB Output is correct
15 Correct 1026 ms 3088 KB Output is correct
16 Correct 1047 ms 3080 KB Output is correct
17 Correct 1082 ms 3072 KB Output is correct
18 Correct 1861 ms 4260 KB Output is correct
19 Correct 1953 ms 4272 KB Output is correct
20 Correct 2027 ms 4296 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 344 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 1 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 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 0 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 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 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 0 ms 332 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 1 ms 408 KB Output is correct
54 Correct 1 ms 332 KB Output is correct
55 Correct 1 ms 332 KB Output is correct
56 Correct 0 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 0 ms 332 KB Output is correct
60 Correct 0 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 716 KB Output is correct
66 Correct 5 ms 716 KB Output is correct
67 Correct 8 ms 716 KB Output is correct
68 Correct 9 ms 836 KB Output is correct
69 Correct 11 ms 956 KB Output is correct
70 Correct 11 ms 844 KB Output is correct
71 Correct 16 ms 1124 KB Output is correct
72 Correct 17 ms 1100 KB Output is correct
73 Correct 8 ms 716 KB Output is correct
74 Correct 8 ms 840 KB Output is correct
75 Correct 8 ms 840 KB Output is correct
76 Correct 8 ms 716 KB Output is correct
77 Correct 8 ms 716 KB Output is correct
78 Correct 8 ms 716 KB Output is correct
79 Correct 8 ms 716 KB Output is correct
80 Correct 9 ms 844 KB Output is correct
81 Correct 1838 ms 4264 KB Output is correct
82 Correct 1838 ms 4384 KB Output is correct
83 Correct 1855 ms 4272 KB Output is correct
84 Correct 1854 ms 4380 KB Output is correct
85 Correct 1850 ms 4380 KB Output is correct
86 Correct 1834 ms 4388 KB Output is correct
87 Correct 1839 ms 4292 KB Output is correct
88 Correct 25 ms 716 KB Output is correct
89 Correct 25 ms 716 KB Output is correct
90 Correct 146 ms 1228 KB Output is correct
91 Correct 149 ms 1292 KB Output is correct
92 Correct 536 ms 2408 KB Output is correct
93 Correct 547 ms 2288 KB Output is correct
94 Correct 1119 ms 3400 KB Output is correct
95 Correct 1127 ms 3276 KB Output is correct
96 Correct 1519 ms 3992 KB Output is correct
97 Correct 1535 ms 3864 KB Output is correct
98 Correct 984 ms 3084 KB Output is correct
99 Correct 980 ms 3072 KB Output is correct
100 Correct 984 ms 3076 KB Output is correct
101 Correct 990 ms 3080 KB Output is correct
102 Correct 989 ms 3140 KB Output is correct
103 Correct 1000 ms 3204 KB Output is correct
104 Correct 993 ms 3080 KB Output is correct
105 Correct 929 ms 3076 KB Output is correct