Submission #1260904

#TimeUsernameProblemLanguageResultExecution timeMemory
1260904rayan_bdCatfish Farm (IOI22_fish)C++20
0 / 100
116 ms4724 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], W[i]});
  }
  /*correct dp:-
   for(int i = 1; i <= N; ++i){
    if(i >= 3) dp[i][2] = mp[i] + mp[i - 1] + dp[i - 2][0];
    dp[i][1] = dp[i - 1][0] + mp[i];
    dp[i][0] = max({dp[i - 1][2], dp[i - 1][1], dp[i - 1][0]});
    ans = max({ans, dp[i][1], dp[i][0]});
   }
   */
  for(int i = 1; i <= N; ++i) sort(mp[i].begin(), mp[i].end());
  for(int i = 1, ptr = 0; i <= N; ++i){
    for(int j = 0; j <= N; ++j){
        while(ptr < mp[i].size() && mp[i][ptr].first <= j){
            cost[i][j] += mp[i][ptr].second;
            ptr += 1;
        }
        if(j >= 1) cost[i][j] += cost[i][j - 1];
    }
  }
  for(int i = 1; i <= N; ++i){
    if(i >= 3){
        for(int j = 0; j < N; ++j){
            for(int k = 0; 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 = 0; j < N; ++j){
        dp[i][j][1] = dp[i - 1][j][0] + cost[i][j];
        ans = max(dp[i][j][1], ans);
    }
    for(int j = 0; j < N; ++j){
        dp[i][j][0] = max({dp[i - 1][j][0], dp[i - 1][j][1], dp[i - 1][j][2]});
        ans = max(ans, dp[i][j][0]);
    }
    for(int j = N - 2; j >= 0; --j){
        dp[i][j][0] = max(dp[i][j][0], dp[i][j + 1][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...