제출 #1224365

#제출 시각아이디문제언어결과실행 시간메모리
1224365trimkus메기 농장 (IOI22_fish)C++20
0 / 100
957 ms2162688 KiB
#include "fish.h" #include <bits/stdc++.h> using namespace std; using ll = long long; void chmax(ll& x, ll y) { x = max(x, y); } long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) { vector<vector<ll>> a(N + 3, vector<ll>(N + 3)); for (int i = 0; i < M; ++i) { a[X[i] + 1][Y[i] + 1] += W[i]; } for (int i = 1; i <= N; ++i) { for (int j = 1; j <= N; ++j) { a[i][j] += a[i][j - 1]; } } vector<vector<vector<ll>>> dp(N + 2, vector<vector<ll>>(N + 2, vector<ll>(2))); for (int i = 2; i <= N; ++i) { for (int j = 0; j <= N; ++j) { for (int k = 0; k < j; ++k) { dp[i][j][1] = max(dp[i][j][1], dp[i - 1][k][1] + a[i - 1][j] - a[i - 1][k]); } for (int k = 0; k <= N; ++k) { if (i == 2) { dp[i][j][1] = a[i - 1][j]; // dp[i][j][0] = a[i - 1][k]; } else { dp[i][j][1] = max({dp[i][j][1], dp[i - 2][k][1] + a[i - 1][max(k, j)], dp[i - 2][k][0] + a[i - 1][j]}); dp[i][j][0] = max({dp[i][j][0], dp[i - 2][k][1] + a[i - 1][k], dp[i - 2][k][0]}); } } for (int k = j; k <= N; ++k) { dp[i][j][0] = max({dp[i][j][0], dp[i - 1][k][1] + a[i][k] - a[i][j], dp[i - 1][k][0]}); } } } ll res = 0; for (int i = 0; i <= N; ++i) { for (int k = 0; k < 2; ++k) { res = max(res, dp[N][i][k]); } } 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...