Submission #626856

# Submission time Handle Problem Language Result Execution time Memory
626856 2022-08-11T21:46:40 Z Noam527 Catfish Farm (IOI22_fish) C++17
9 / 100
131 ms 25332 KB
#include "fish.h"
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const int N = 100005;
vector<pair<int, int>> Y[N];
int c[N];
vector<ll> D[N], F[N];
ll E[N];

ll max_weights(int n, int m, vector<int> x, vector<int> y,
                      vector<int> w) {
	for (int i = 0; i < m; i++)
		Y[x[i]].emplace_back(y[i], w[i]);
	for (int i = 0; i < n; i++)
		sort(Y[i].begin(), Y[i].end()), c[i] = Y[i].size();

	// initialize column 0:
	E[0] = 0;
	F[0].resize(c[0], -(ll)1e18);
	D[0].resize(c[0]);
	if (c[0]) {
		D[0][0] = Y[0][0].second;
		for (int j = 1; j < c[0]; j++) {
			D[0][j] = D[0][j - 1] + Y[0][j].second;
		}
	}
	// begin dp:
	for (int i = 1; i < n; i++) {
		E[i] = E[i - 1];
		for (int j = 0; j < c[i - 1]; j++)
			E[i] = max(max(E[i], D[i - 1][j]), F[i - 1][j]);
		if (!c[i]) continue;

		D[i].resize(c[i]);
		F[i].resize(c[i]);

		vector<ll> below(c[i]), above(c[i]);
		// compute below
		int z = 0;
		ll bestfound = -(ll)1e18;
		for (int k = 0; k < c[i]; k++) {
			while (z < c[i - 1] && Y[i - 1][z].first < Y[i][k].first) {
				bestfound = max(bestfound, D[i - 1][z]);
				z++;
			}
			below[k] = bestfound;
		}
		// compute above
		z = c[i - 1] - 1;
		bestfound = -(ll)1e18;
		for (int k = c[i] - 1; k >= 0; k--) {
			while (z >= 0 && Y[i - 1][z].first > Y[i][k].first) {
				bestfound = max(bestfound, F[i - 1][z]);
				z--;
			}
			above[k] = bestfound;
		}
		// compute D:
		ll bestF = -(ll)1e18;
		if (c[i - 1])
			ll bestF = *max_element(F[i - 1].begin(), F[i - 1].end());
		D[i][0] = max(max(below[0], E[i - 1]), bestF) + Y[i][0].second;
		for (int j = 1; j < c[i]; j++) {
			D[i][j] = max(below[j], D[i][j - 1]) + Y[i][j].second;
		}
		// compute F:
		F[i][c[i] - 1] = max(E[i - 1], above[c[i] - 1]) + Y[i][c[i] - 1].second;
		for (int j = c[i] - 2; j >= 0; j--) {
			F[i][j] = max(above[j], F[i][j - 1]) + Y[i][j].second;
		}
	}
	ll result = E[n - 1];
	for (int j = 0; j < c[n - 1]; j++) {
		result = max(result, F[n - 1][j]);
	}
	return result;
}

Compilation message

fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:63:7: warning: unused variable 'bestF' [-Wunused-variable]
   63 |    ll bestF = *max_element(F[i - 1].begin(), F[i - 1].end());
      |       ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 33 ms 12232 KB Output is correct
2 Correct 40 ms 13256 KB Output is correct
3 Correct 5 ms 8404 KB Output is correct
4 Correct 4 ms 8404 KB Output is correct
5 Correct 114 ms 23908 KB Output is correct
6 Correct 131 ms 25332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7332 KB Output is correct
2 Correct 67 ms 16652 KB Output is correct
3 Correct 78 ms 18836 KB Output is correct
4 Correct 33 ms 12228 KB Output is correct
5 Correct 42 ms 13248 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 3 ms 7252 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 4 ms 8404 KB Output is correct
11 Correct 4 ms 8404 KB Output is correct
12 Correct 33 ms 12912 KB Output is correct
13 Correct 40 ms 14072 KB Output is correct
14 Correct 35 ms 12296 KB Output is correct
15 Correct 38 ms 12948 KB Output is correct
16 Correct 33 ms 12400 KB Output is correct
17 Correct 39 ms 12936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8520 KB Output is correct
2 Correct 4 ms 8404 KB Output is correct
3 Incorrect 32 ms 14616 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7324 KB Output is correct
4 Correct 5 ms 7252 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Incorrect 5 ms 7380 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '163829363203'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7324 KB Output is correct
4 Correct 5 ms 7252 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Incorrect 5 ms 7380 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '163829363203'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7324 KB Output is correct
4 Correct 5 ms 7252 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Incorrect 5 ms 7380 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '163829363203'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8520 KB Output is correct
2 Correct 4 ms 8404 KB Output is correct
3 Incorrect 32 ms 14616 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 12232 KB Output is correct
2 Correct 40 ms 13256 KB Output is correct
3 Correct 5 ms 8404 KB Output is correct
4 Correct 4 ms 8404 KB Output is correct
5 Correct 114 ms 23908 KB Output is correct
6 Correct 131 ms 25332 KB Output is correct
7 Correct 5 ms 7332 KB Output is correct
8 Correct 67 ms 16652 KB Output is correct
9 Correct 78 ms 18836 KB Output is correct
10 Correct 33 ms 12228 KB Output is correct
11 Correct 42 ms 13248 KB Output is correct
12 Correct 4 ms 7252 KB Output is correct
13 Correct 3 ms 7252 KB Output is correct
14 Correct 4 ms 7252 KB Output is correct
15 Correct 4 ms 7252 KB Output is correct
16 Correct 4 ms 8404 KB Output is correct
17 Correct 4 ms 8404 KB Output is correct
18 Correct 33 ms 12912 KB Output is correct
19 Correct 40 ms 14072 KB Output is correct
20 Correct 35 ms 12296 KB Output is correct
21 Correct 38 ms 12948 KB Output is correct
22 Correct 33 ms 12400 KB Output is correct
23 Correct 39 ms 12936 KB Output is correct
24 Correct 5 ms 8520 KB Output is correct
25 Correct 4 ms 8404 KB Output is correct
26 Incorrect 32 ms 14616 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341'
27 Halted 0 ms 0 KB -