Submission #1028114

#TimeUsernameProblemLanguageResultExecution timeMemory
1028114NeroZeinCatfish Farm (IOI22_fish)C++17
61 / 100
1088 ms51144 KiB
#include "fish.h" #include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast,fast-math,unroll-loops") #pragma GCC target("avx2,fma") long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) { vector<vector<pair<int, int>>> in_col(N); for (int i = 0; i < M; ++i) { in_col[X[i]].push_back({Y[i], W[i]}); } for (int i = 0; i < N; ++i) { sort(in_col[i].begin(), in_col[i].end()); in_col[i].push_back({N, 0}); } vector<vector<long long>> pre(N); for (int col = 1; col < N; ++col) { pre[col].resize(in_col[col].size()); for (int i = 0; i < (int) in_col[col].size(); ++i) { int ptr = 0; long long sum = 0; while (ptr < (int) in_col[col - 1].size() && in_col[col - 1][ptr].first < in_col[col][i].first) { sum += in_col[col - 1][ptr].second; ptr++; } pre[col][i] = sum; } } vector<vector<long long>> nxt(N); for (int col = 0; col < N - 1; ++col) { nxt[col].resize(in_col[col].size()); for (int i = 0; i < (int) in_col[col].size(); ++i) {//M tot int ptr = 0; long long sum = 0; while (ptr < (int) in_col[col + 1].size() && in_col[col + 1][ptr].first < in_col[col][i].first) { sum += in_col[col + 1][ptr].second; ptr++; } nxt[col][i] = sum; } } vector<vector<vector<long long>>> dp(N + 1); for (int i = 0; i < N + 1; ++i) { dp[i].resize(2); dp[i][0].assign(2, -1); dp[i][1].assign(2, -1); } dp[0][0][0] = 0; for (int col = 0; col < N; ++col) { int sz = (int) in_col[col].size(); for (int f = 0; f < 2; ++f) { for (int f2 = 0; f2 < 2; ++f2) { if (dp[col][f][f2] == -1) { continue; } if (f) { long long s = 0; for (int i = 0; i < sz; ++i) { long long w = s; if (col < N - 1) { w += nxt[col][i]; } dp[col + 1][1][0] = max(dp[col + 1][1][0], dp[col][f][f2] + w); s -= in_col[col][i].second; } dp[col + 1][0][0] = max(dp[col + 1][0][0], dp[col][f][f2]); } else { long long s = 0; for (int i = 0; i < sz; ++i) { long long w = s; if (f2) { w += pre[col][i]; } dp[col + 1][0][1] = max(dp[col + 1][0][1], dp[col][f][f2] + w); s -= in_col[col][i].second; } s = 0; if (col < N - 1) { s = nxt[col][sz - 1]; } if (f2) { s += pre[col][sz - 1]; } dp[col + 1][1][0] = max(dp[col + 1][1][0], dp[col][f][f2] + s); } } } } long long ans = 0; for (int f = 0; f < 2; ++f) { for (int f2 = 0; f2 < 2; ++f2) { ans = max(ans, dp[N][f][f2]); } } return ans; }
#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...