제출 #1261055

#제출 시각아이디문제언어결과실행 시간메모리
1261055rayan_bd메기 농장 (IOI22_fish)C++20
0 / 100
140 ms7356 KiB
#include "fish.h" #include <bits/stdc++.h> using namespace std; long long dp[305][305][3], cost[305][305]; // 0 -> block, 1 -> take the single , 2 -> take two vector<pair<int, int>> mp[305]; long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) { long long ans = 0; for(int i = 0; i < M; ++i){ mp[X[i] + 1].push_back({Y[i] + 1, W[i]}); } for(int i = 1; i <= N; ++i) sort(mp[i].begin(), mp[i].end()); for(int i = 1; i <= N; ++i){ int ptr = 0; for(int j = 1; j <= N; ++j){ while(ptr < mp[i].size() && mp[i][ptr].first <= j){ cost[i][j] += mp[i][ptr].second; ptr += 1; } cost[i][j] += cost[i][j - 1]; } } for(int i = 1; i <= N; ++i){ if(i >= 2){ for(int j = 1; j <= N; ++j){ for(int k = 1; k <= N; ++k){ dp[i][j][2] = max(dp[i][j][2], dp[i - 2][k][0] + cost[i][j] + cost[i - 1][k]); } } } for(int j = 1; j <= N; ++j){ for(int k = j; k <= N; ++k){ dp[i][j][1] = max(dp[i][j][1], dp[i - 1][k][0] + cost[i][j]); if(i == 1) dp[i][j][2] = dp[i][j][1]; } ans = max(dp[i][j][1], ans); } auto get = [&](int i, int l, int r) -> long long{ if(l > r) return 0; return cost[i][r] - cost[i][l - 1]; }; for(int j = 1; j <= N; ++j){ for(int k = 1; k <= j; ++k){ dp[i][j][0] = max({dp[i][j][0], dp[i - 1][k][0], dp[i - 1][j][1], dp[i - 1][j][2]}); } for(int k = j + 1; k <= N; ++k){ dp[i][j][0] = max(dp[i][j][0], dp[i - 1][k][0] + get(i, j + 1, k)); } ans = max(ans, dp[i][j][0]); } } 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...