Submission #732557

#TimeUsernameProblemLanguageResultExecution timeMemory
732557math_rabbit_1028Catfish Farm (IOI22_fish)C++17
52 / 100
1078 ms297680 KiB
#include "fish.h" #include <bits/stdc++.h> #include <vector> using namespace std; long long zero[3030], full[3030], dp[2][3030][3030], grid[3030][3030], sum[3030][3030]; long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) { for (int i = 0; i < M; i++) { X[i] += 1; Y[i] += 1; grid[X[i]][Y[i]] = W[i]; } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) sum[i][j] = sum[i][j - 1] + grid[i][j]; } for (int j = 1; j < N; j++) dp[0][0][j] = dp[1][0][j] = -1e18; full[0] = -1e18; for (int i = 2; i <= N + 1; i++) { for (int k = 1; k < N; k++) zero[i] = max(zero[i], dp[1][i - 1][k] + sum[i][k]); zero[i] = max(zero[i], zero[i - 1]); zero[i] = max(zero[i], full[i - 1] + sum[i][N]); for (int k = 1; k < N; k++) full[i] = max(full[i], dp[0][i - 1][k] + sum[i - 1][N] - sum[i - 1][k]); full[i] = max(full[i], full[i - 1]); full[i] = max(full[i], zero[i - 2] + sum[i - 1][N]); full[i] = max(full[i], full[i - 2] + sum[i - 1][N]); for (int l = 1; l < N; l++) full[i] = max(full[i], dp[1][i - 2][l] + sum[i - 1][N]); long long val0 = 0, val1 = 0; for (int k = 1; k < N; k++) { val0 = max(val0, dp[0][i - 1][k] - sum[i - 1][k]); val1 = max(val1, dp[1][i - 1][k] + sum[i][k]); } for (int j = 1; j < N; j++) { dp[0][i][j] = max(dp[0][i][j], val0 + sum[i - 1][j]); dp[1][i][j] = max(dp[1][i][j], val1 - sum[i][j]); dp[1][i][j] = max(dp[1][i][j], full[i - 1] + sum[i][N] - sum[i][j]); dp[0][i][j] = max(dp[0][i][j], zero[i - 2] + sum[i - 1][j]); dp[0][i][j] = max(dp[0][i][j], full[i - 2] + sum[i - 1][N]); } long long val2 = 0; for (int j = 1; j < N; j++) { val2 = max(val2, dp[1][i - 2][j]); dp[0][i][j] = max(dp[0][i][j], val2 + sum[i - 1][j]); } long long val3 = 0; for (int j = N - 1; j >= 1; j--) { val3 = max(val3, dp[1][i - 2][j] + sum[i - 1][j]); dp[0][i][j] = max(dp[0][i][j], val3); } } long long res = 0; res = zero[N + 1]; return res; }
#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...