Submission #1032398

#TimeUsernameProblemLanguageResultExecution timeMemory
103239842kangarooCatfish Farm (IOI22_fish)C++17
100 / 100
111 ms28756 KiB
#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) { 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; if (dpU[laP] - su > dpU[be] - beSu) { be = laP; beSu = su; } laP++; } dpNU[j] = dpU[be] + su - beSu; } laP = fi[i - 1].size() - 1; su = 0; beSu = 0; be = fi[i - 1].size() - 1; for (int j = fi[i].size() - 1; j >= 0; --j) { while (laP >= 0 && fi[i - 1][laP].x > fi[i][j].x) { laP--; if (dpD[laP] - su > dpD[be] - beSu) { be = laP; beSu = su; } } dpND[j] = max(dpD[be] + su - beSu, dpNU[j]); su += fi[i][j].w; } laP = 0; su = 0; for (int j = 0; j < fi[i - 1].size(); ++j) { while (laP < fi[i].size() && (j == fi[i - 1].size() - 1 || fi[i - 1][j + 1].x > fi[i][laP].x)) { su += fi[i][laP].w; dp0[laP] = dpD[j] + su; laP++; } dp0[laP - 1] = max(dpD[j] + su, dp0[laP - 1]); } for (int j = dp0.size() - 1; j >= 0; --j) { dpNU[j] = max(dp0[j], dpNU[j]); } dpD = dpND; dpU = dpNU; } return max(*max_element(dpU.begin(), dpU.end()), *max_element(dpD.begin(), dpD.end())); }

Compilation message (stderr)

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:33:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<CaF>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |    while (laP < fi[i - 1].size() && (j == fi[i].size() - 1 || fi[i - 1][laP].x < fi[i][j + 1].x)) {
      |           ~~~~^~~~~~~~~~~~~~~~~~
fish.cpp:33:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<CaF>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |    while (laP < fi[i - 1].size() && (j == fi[i].size() - 1 || fi[i - 1][laP].x < fi[i][j + 1].x)) {
      |                                      ~~^~~~~~~~~~~~~~~~~~~
fish.cpp:60:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<CaF>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   for (int j = 0; j < fi[i - 1].size(); ++j) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:61:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<CaF>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |    while (laP < fi[i].size() && (j == fi[i - 1].size() - 1 || fi[i - 1][j + 1].x > fi[i][laP].x)) {
      |           ~~~~^~~~~~~~~~~~~~
fish.cpp:61:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<CaF>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |    while (laP < fi[i].size() && (j == fi[i - 1].size() - 1 || fi[i - 1][j + 1].x > fi[i][laP].x)) {
      |                                  ~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...