Submission #839078

#TimeUsernameProblemLanguageResultExecution timeMemory
839078abczzCatfish Farm (IOI22_fish)C++17
100 / 100
227 ms42444 KiB
#include "fish.h" #include <iostream> #include <vector> #include <algorithm> #include <array> #include <map> #include <queue> #define ll long long using namespace std; vector <array<ll, 2>> V[100000]; vector <ll> pre; vector <array<ll, 3>> dp[100000]; long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) { ll f = -1e18, j, k, l, s = 0, t = 0, v, x, u, p = -1e18, mx, mx2, cur; map <ll, ll> mp; for (int i=0; i<M; ++i) { V[X[i]].push_back({Y[i], W[i]}); } for (int i=0; i<N; ++i) { sort(V[i].begin(), V[i].end()); } j = 0; s = 0; for (auto [y, w] : V[1]) { s += w; dp[0].push_back({y, 0, (ll)-1e18}); f = max(f, s); } for (int i=1; i<N; ++i) { if (i >= 3) { j = 0; s = 0; for (auto [y, w, a] : dp[i-3]) { w = max(w, a); while (j < V[i-2].size() && V[i-2][j][0] <= y) { s += V[i-2][j][1]; ++j; } p = max(p, s+w); } } mp.clear(); mx = mx2 = -1e18, s = 0; if (i >= 2) { j = 0; for (auto [y, w, a] : dp[i-2]) { w = max(w, a); while (j < V[i-1].size() && V[i-1][j][0] <= y) { s += V[i-1][j][1]; ++j; } mx = max(mx, w); mx2 = max(mx2, w+s); } } for (auto [y, w] : V[i-1]) { ++mp[y]; } if (i != N-1) { for (auto [y, w] : V[i+1]) { ++mp[y]; } } s = j = k = t = 0; v = x = -1e18; pre.clear(); for (auto [y, w, a] : dp[i-1]) { while (j < V[i].size() && V[i][j][0] <= y) { s += V[i][j][1]; ++j; } while (k < V[i-1].size() && V[i-1][k][0] <= y) { t += V[i-1][k][1]; ++k; } v = max(v, max(w, a)+s); x = max(x, w-t); } s = j = k = t = l = u = 0; for (auto [y, z] : mp) { while (j < V[i].size() && V[i][j][0] <= y) { s += V[i][j][1]; ++j; } while (k < V[i-1].size() && V[i-1][k][0] <= y) { t += V[i-1][k][1]; ++k; } while (i != N-1 && l < V[i+1].size() && V[i+1][l][0] <= y) { u += V[i+1][l][1]; ++l; } cur = max(max(t, p+t), max(mx2, mx+t)); //cout << v << " " << x << " " << s << " " << t << endl; //cout << cur << endl; cur = max(cur, x+t); //cout << cur << endl; dp[i].push_back({y, cur, v-s}); //cout << i << " " << y << " " << cur << "/" << v-s << endl; cur = max(cur, v-s); f = max(f, cur + u); } } return f; }

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:37:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         while (j < V[i-2].size() && V[i-2][j][0] <= y) {
      |                ~~^~~~~~~~~~~~~~~
fish.cpp:50:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         while (j < V[i-1].size() && V[i-1][j][0] <= y) {
      |                ~~^~~~~~~~~~~~~~~
fish.cpp:70:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |       while (j < V[i].size() && V[i][j][0] <= y) {
      |              ~~^~~~~~~~~~~~~
fish.cpp:74:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |       while (k < V[i-1].size() && V[i-1][k][0] <= y) {
      |              ~~^~~~~~~~~~~~~~~
fish.cpp:83:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |       while (j < V[i].size() && V[i][j][0] <= y) {
      |              ~~^~~~~~~~~~~~~
fish.cpp:87:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |       while (k < V[i-1].size() && V[i-1][k][0] <= y) {
      |              ~~^~~~~~~~~~~~~~~
fish.cpp:91:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |       while (i != N-1 && l < V[i+1].size() && V[i+1][l][0] <= y) {
      |                          ~~^~~~~~~~~~~~~~~
#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...