Submission #1075308

# Submission time Handle Problem Language Result Execution time Memory
1075308 2024-08-26T02:05:51 Z Gromp15 Catfish Farm (IOI22_fish) C++17
61 / 100
1000 ms 54608 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include "fish.h"
#define ll long long
#define ar array
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
using namespace std;
 
const ll INF = 1e18;
template<typename T> bool ckmin(T &a, const T &b ) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b ) { return a < b ? a = b, 1 : 0; }

long long max_weights(int n, int m, std::vector<int> x, std::vector<int> y, std::vector<int> w) {
	vector<vector<ar<ll, 2>>> each(n);
	for (int i = 0; i < m; i++) {
		each[x[i]].push_back({y[i], w[i]});
		each[x[i]].push_back({y[i]-1, 0});
	}
	for (int i = 0; i < n; i++) each[i].push_back({n-1, 0}), each[i].push_back({-1, 0});
	for (int i = 0; i < n; i++) {
		sort(all(each[i]));
		vector<ar<ll, 2>> nw;
		ll s = 0;
		for (int j = 0; j < sz(each[i]); j++) {
			int r = j;
			while (r+1 < sz(each[i]) && each[i][r+1][0] == each[i][r][0]) r++;
			for (int k = j; k <= r; k++) s += each[i][k][1];
			nw.push_back({each[i][j][0], s});
			j = r;
		}
		swap(each[i], nw);
	}
	vector<ar<ll, 2>> dp;
	auto query = [&](int pos, int x) {
		return (*prev(upper_bound(all(each[pos]), ar<ll, 2>{x, LLONG_MAX})))[1];
	};
	vector<vector<ll>> l(n), r(n);
	for (int i = 0; i < n; i++) {
		l[i].resize(sz(each[i]));
		r[i].resize(sz(each[i]));
		for (int k = 0; k < sz(each[i]); k++) {
			if (i) l[i][k] = query(i - 1, each[i][k][0]);
			if (i+1 < n) r[i][k] = query(i + 1, each[i][k][0]);
		}
	}
	for (int i = 0; i < n; i++) {
		vector<ar<ll, 2>> dp2;
		const int N = sz(each[i]);
		dp2.resize(N+1, {-INF, -INF});
		if (!i) {
			dp2[0][0] = 0, dp2[N][1] = 0;
			swap(dp, dp2);
		}
		else {
			for (int j = 1; j <= N; j++) {
				for (int k = 0; k < sz(dp); k++) {
					if (each[i][j-1][0] >= (k ? each[i-1][k-1][0] : -1)) {
						assert(l[i][j-1] >= (k ? each[i-1][k-1][1] : 0));
						ckmax(dp2[j][j==N], dp[k][0] + l[i][j-1] - (k ? each[i-1][k-1][1] : 0));
						if (k == 1) ckmax(dp2[j][j==N], dp[k][1]);
					}
				}
			}
			ckmax(dp2[0][0], dp[1][1]);
			for (int j = 1; j <= N; j++) {
				for (int k = 1; k < sz(dp); k++) {
					if (each[i][j-1][0] <= each[i-1][k-1][0]) {
						assert(r[i-1][k-1] >= each[i][j-1][1]);
						ckmax(dp2[j][1], dp[k][1] + r[i-1][k-1] - each[i][j-1][1]);
					}
				}
			}
			swap(dp, dp2);
		}
	}
	ll ans = -INF;
	for (auto [x, y] : dp) ckmax(ans, x), ckmax(ans, y);
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 67 ms 24020 KB Output is correct
2 Correct 98 ms 27188 KB Output is correct
3 Correct 31 ms 18268 KB Output is correct
4 Correct 30 ms 18412 KB Output is correct
5 Correct 161 ms 44172 KB Output is correct
6 Correct 196 ms 54608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Execution timed out 1081 ms 31584 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 18264 KB Output is correct
2 Correct 34 ms 18244 KB Output is correct
3 Correct 68 ms 20564 KB Output is correct
4 Correct 52 ms 21072 KB Output is correct
5 Correct 78 ms 25684 KB Output is correct
6 Correct 85 ms 24952 KB Output is correct
7 Correct 77 ms 25468 KB Output is correct
8 Correct 85 ms 25672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 432 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 1 ms 344 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 432 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 1 ms 344 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 500 KB Output is correct
17 Correct 80 ms 4688 KB Output is correct
18 Correct 49 ms 4952 KB Output is correct
19 Correct 37 ms 4952 KB Output is correct
20 Correct 33 ms 4956 KB Output is correct
21 Correct 38 ms 4696 KB Output is correct
22 Correct 113 ms 9300 KB Output is correct
23 Correct 9 ms 1372 KB Output is correct
24 Correct 35 ms 3672 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 7 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 432 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 1 ms 344 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 500 KB Output is correct
17 Correct 80 ms 4688 KB Output is correct
18 Correct 49 ms 4952 KB Output is correct
19 Correct 37 ms 4952 KB Output is correct
20 Correct 33 ms 4956 KB Output is correct
21 Correct 38 ms 4696 KB Output is correct
22 Correct 113 ms 9300 KB Output is correct
23 Correct 9 ms 1372 KB Output is correct
24 Correct 35 ms 3672 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 7 ms 1368 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 523 ms 21680 KB Output is correct
29 Execution timed out 1048 ms 27320 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 18264 KB Output is correct
2 Correct 34 ms 18244 KB Output is correct
3 Correct 68 ms 20564 KB Output is correct
4 Correct 52 ms 21072 KB Output is correct
5 Correct 78 ms 25684 KB Output is correct
6 Correct 85 ms 24952 KB Output is correct
7 Correct 77 ms 25468 KB Output is correct
8 Correct 85 ms 25672 KB Output is correct
9 Correct 88 ms 28728 KB Output is correct
10 Correct 81 ms 16644 KB Output is correct
11 Correct 116 ms 33160 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 33 ms 18260 KB Output is correct
19 Correct 32 ms 18260 KB Output is correct
20 Correct 30 ms 18256 KB Output is correct
21 Correct 32 ms 18260 KB Output is correct
22 Correct 88 ms 30032 KB Output is correct
23 Correct 125 ms 38876 KB Output is correct
24 Correct 137 ms 40016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 24020 KB Output is correct
2 Correct 98 ms 27188 KB Output is correct
3 Correct 31 ms 18268 KB Output is correct
4 Correct 30 ms 18412 KB Output is correct
5 Correct 161 ms 44172 KB Output is correct
6 Correct 196 ms 54608 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Execution timed out 1081 ms 31584 KB Time limit exceeded
9 Halted 0 ms 0 KB -