Submission #966266

# Submission time Handle Problem Language Result Execution time Memory
966266 2024-04-19T15:44:01 Z 42kangaroo Catfish Farm (IOI22_fish) C++17
3 / 100
130 ms 28756 KB
#include "fish.h"
#include "bits/stdc++.h"

#include <vector>

struct CaF {
	long long x, w;
};

using ll = long long;

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
	using namespace std;
	vector<vector<CaF>> fi(N);
	for (int i = 0; i < N; ++i) {
		fi[i].push_back({-1, 0});
	}
	for (int i = 0; i < M; ++i) {
		fi[X[i]].push_back({Y[i], W[i]});
	}
	for (int i = 0; i < N; ++i) {
		sort(fi[i].begin(), fi[i].end(), [](const CaF &l, const CaF &r) { return l.x < r.x; });
	}
	vector<ll> dpU(fi[0].size()), dpD(fi[0].size());
	for (int i = 1; i < N; ++i) {
		vector<ll> dpNU(fi[i].size()), dpND(fi[i].size()), dp0(fi[i].size());
		int laP = 0;
		ll su = 0;
		ll beSu = 0;
		int be = 0;
		for (int j = 0; j < fi[i].size(); ++j) {
			int lalaP = laP;
			while (laP < fi[i - 1].size() && (j == fi[i].size() - 1 || fi[i - 1][laP].x <= fi[i][j + 1].x)) {
				su += fi[i - 1][laP++].w;
			}
			ll doSu = su;
			for (int k = laP - 1; k >= lalaP; --k) {
				if (dpU[k] - doSu > dpU[be] - beSu) {
					be = k;
					beSu = doSu;
				}
				doSu -= fi[i - 1][k].w;
			}
			dpNU[j] = dpU[be] + su - beSu;
		}
		laP = fi[i - 1].size() - 1;
		su = 0;
		beSu = 0;
		be = 0;
		for (int j = fi[i].size() - 1; j >= 0; --j) {
			int lalaP = laP;
			while (laP >= 0 && fi[i - 1][laP].x > fi[i][j].x) {
				su += fi[i - 1][laP--].w;
			}
			ll doSu = su;
			for (int k = laP + 1; k <= lalaP; ++k) {
				if (dpD[k] - doSu > dpD[be] - beSu) {
					be = k;
					beSu = doSu;
				}
				doSu -= fi[i - 1][k].w;
			}
			dpND[j] = max(dpD[be] + su - beSu, dpNU[j]);
		}
		laP = 0;
		su = 0;
		for (int j = 0; j < fi[i - 1].size(); ++j) {
			while (laP < fi[i].size() && fi[i - 1][j].x >= fi[i][laP].x) {
				su += fi[i][laP++].w;
			}
			dp0[min(laP, (int)fi[i].size() - 1)] = dpD[j] + su;
		}
		for (int j = dp0.size() - 2; j >=0; --j) {
			dp0[j] = max(dp0[j], dp0[j + 1]);
			dpNU[j] = max(dp0[j], dpNU[j]);
			dpND[j] = max(dpND[j], dpNU[j]);
		}
		dpD = dpNU;
		dpU = dpNU;
	}
	return max(*max_element(dpU.begin(), dpU.end()), *max_element(dpD.begin(), dpD.end()));
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:32:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<CaF>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |   for (int j = 0; j < fi[i].size(); ++j) {
      |                   ~~^~~~~~~~~~~~~~
fish.cpp:34:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<CaF>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |    while (laP < fi[i - 1].size() && (j == fi[i].size() - 1 || fi[i - 1][laP].x <= fi[i][j + 1].x)) {
      |           ~~~~^~~~~~~~~~~~~~~~~~
fish.cpp:34:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<CaF>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |    while (laP < fi[i - 1].size() && (j == fi[i].size() - 1 || fi[i - 1][laP].x <= fi[i][j + 1].x)) {
      |                                      ~~^~~~~~~~~~~~~~~~~~~
fish.cpp:68:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<CaF>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   for (int j = 0; j < fi[i - 1].size(); ++j) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:69:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<CaF>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |    while (laP < fi[i].size() && fi[i - 1][j].x >= fi[i][laP].x) {
      |           ~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 38 ms 11080 KB Output is correct
2 Correct 43 ms 12996 KB Output is correct
3 Correct 12 ms 5724 KB Output is correct
4 Correct 13 ms 5724 KB Output is correct
5 Correct 111 ms 27884 KB Output is correct
6 Correct 130 ms 28756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 63 ms 17480 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '80958394776886'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 5724 KB Output is correct
2 Incorrect 13 ms 5760 KB 1st lines differ - on the 1st token, expected: '882019', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 5724 KB Output is correct
2 Incorrect 13 ms 5760 KB 1st lines differ - on the 1st token, expected: '882019', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 11080 KB Output is correct
2 Correct 43 ms 12996 KB Output is correct
3 Correct 12 ms 5724 KB Output is correct
4 Correct 13 ms 5724 KB Output is correct
5 Correct 111 ms 27884 KB Output is correct
6 Correct 130 ms 28756 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Incorrect 63 ms 17480 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '80958394776886'
9 Halted 0 ms 0 KB -