Submission #1036932

# Submission time Handle Problem Language Result Execution time Memory
1036932 2024-07-27T20:04:57 Z thatsgonzalez Catfish Farm (IOI22_fish) C++17
0 / 100
814 ms 2097152 KB
#include "fish.h"

#include <vector>
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x.size())

vector<vector<pair<int,int>>> fish;

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
    fish.resize(N);
    
    for(int i = 0; i<M; i++){
      fish[X[i]].pb({Y[i],W[i]});
    }

    for(auto &x: fish){
      sort(all(x));
    }

    vector<vector<long long>> pref(N,vector<long long>(N+1,0));

    for(int i = 0; i<N; i++){
        int ind = 0;
        if(fish[i][0].f == 0){
            pref[i][1] = fish[i][0].s; ind++;
        }  
        for(int j = 1; j<N; j++){
            pref[i][j+1] = pref[i][j];      
            if(fish[i][ind].f == j){
                pref[i][j+1] += fish[i][ind].s;
                ind++;
            }
        }
    }

    /*
        0 : xx
        1 : xy
        2 : yx
        3 : yy
    */

    long long dp[N][N+1][N+1]; for(auto &x: dp) for(auto &y: x) for(auto &z: y) z = 0;
    vector<long long> mx(N+1); for(auto &x: mx) x = 0;
    vector<long long> indx(N+1); for(auto &x: indx) x = 0;

    for(int i = 0; i<N+1; i++){
        for(int j = 0; j<N+1; j++){
            dp[1][i][j] = (max(0LL,pref[0][j]-pref[0][i])) + (max(0LL,pref[1][i] - pref[1][j]));
            if(mx[j]<dp[1][i][j]){
                mx[i] = dp[1][i][j];
                indx[i] = j;
            }
        }
    }

    for(int i = 2; i<N; i++){

        vector<long long> nmx(N+1,0);
        vector<long long> nindx(N+1);

        for(int j = 0; j<N+1; j++){

            for(int k = 0; k<N+1; k++){
                long long temp = mx[k] + max(0LL,pref[i][k]-pref[i][j]) + max(0LL,pref[i-1][j]-pref[i-1][indx[k]]);
                if(dp[i][j][k] < temp){
                    dp[i][j][k] = temp;
                    nmx[j] = temp;
                    nindx[j] = k;
                }
            }
        }
    
        mx = nmx;
        indx = nindx;

    }

    long long ans = 0;
    for(auto &x: dp[N-1]){
        for(auto &y: x){
            ans = max(ans,y);
        }
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 755 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 814 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 814 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 755 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -