Submission #1032011

# Submission time Handle Problem Language Result Execution time Memory
1032011 2024-07-23T09:57:53 Z 42kangaroo Catfish Farm (IOI22_fish) C++17
3 / 100
95 ms 28648 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 = 1e9;
		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 = 1e9;
		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)] = max(dpD[j] + su, dp0[laP - 1]);
		}
		for (int j = dp0.size() - 1; j >= 0; --j) {
			dpNU[j] = max(dp0[j], dpNU[j]);
			dpND[j] = max(dpND[j], dpNU[j]);
		}
		dpD = dpND;
		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 31 ms 10944 KB Output is correct
2 Correct 37 ms 13076 KB Output is correct
3 Correct 13 ms 5724 KB Output is correct
4 Correct 11 ms 5788 KB Output is correct
5 Correct 92 ms 27944 KB Output is correct
6 Correct 95 ms 28648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 54 ms 17676 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '80958286105549'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 5724 KB Output is correct
2 Incorrect 11 ms 5724 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 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 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 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 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 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 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 11 ms 5724 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 31 ms 10944 KB Output is correct
2 Correct 37 ms 13076 KB Output is correct
3 Correct 13 ms 5724 KB Output is correct
4 Correct 11 ms 5788 KB Output is correct
5 Correct 92 ms 27944 KB Output is correct
6 Correct 95 ms 28648 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Incorrect 54 ms 17676 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '80958286105549'
9 Halted 0 ms 0 KB -