제출 #1261085

#제출 시각아이디문제언어결과실행 시간메모리
1261085rayan_bd메기 농장 (IOI22_fish)C++20
0 / 100
750 ms149988 KiB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
long long dp[3005][3005][2], cost[305][305]; // 0 -> block, 1 -> take the single , 2 -> take two
vector<pair<int, int>> mp[3005];
long long get_answer(int N, int M, vector<int> X, vector<int> Y, vector<int> W){
    for(int i = 0; i <= N; ++i){
        mp[i].clear();
    }
    memset(dp, 0, sizeof(dp));
    memset(cost, 0, sizeof(cost));
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] + get(i - 1, k + 1, j), dp[i - 1][j][1], dp[i - 1][j][2]});
        }
        ans = max(ans, dp[i][j][0]);
    }
  }
  return ans;
}
long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
  long long ans = get_answer(N, M, X, Y, W);
  for(int i = 0; i < M; ++i){
    X[i] = N - X[i] - 1;
  }
  ans = max(ans, get_answer(N, M, X, Y, W));
  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...