Submission #1316924

#TimeUsernameProblemLanguageResultExecution timeMemory
1316924opeleklanosCarnival Tickets (IOI20_tickets)C++20
11 / 100
1 ms824 KiB
#include <iostream>
#include <algorithm>
#include <vector>
#include "tickets.h"
using namespace std;

#define ll long long

vector<vector<int>> x;
vector<vector<pair<ll, ll>>> dp;
int n, m;

pair<ll, ll> makeDp(int indx, int used_high){
    if(used_high >= indx+1) return{-1, -1};
    if(dp[indx][used_high].first != -1) return dp[indx][used_high];
    if(indx == 0){
        if(used_high == 1) return dp[indx][used_high] = {x[indx][m-1], m-1};
        if(used_high == 0) return dp[indx][used_high] = {-x[indx][0], 0};
    }
    dp[indx][used_high] = {makeDp(indx-1, used_high).first - (ll)x[indx][0], 0};
    if(used_high && dp[indx][used_high].first < makeDp(indx-1, used_high-1).first + (ll)x[indx][m-1]){
        dp[indx][used_high] = {makeDp(indx-1, used_high-1).first + (ll)x[indx][m-1], m-1};
    }
    return dp[indx][used_high];
}

ll find_maximum(int k, vector<vector<int>> x1){
    x = x1;
    n = x.size();
    m = x[0].size();
    if(m == 1){
        sort(x.begin(), x.end());
        ll ans = 0;
        for(int i = 0; i<n/2; i++) ans -= (ll)x[i][0];
        for(int i = n/2; i<n; i++) ans += (ll)x[i][0];
        vector<vector<int>> arr(n, vector<int>(1, 0));
        allocate_tickets(arr);
        return ans;
    }
    else{
        dp.assign(n, vector<pair<ll, ll>>(n, pair<ll, ll>(-1, -1)));
        int ans = makeDp(n-1, n/2).first;
        vector<vector<int>> arr(n, vector<int>(m, -1));
        int uh = n/2;
        for(int i = n-1; i>=0; i--){
            arr[i][dp[i][uh].second] = 0;
            if(dp[i][uh].second == m-1) uh--;
            
        }
        allocate_tickets(arr);
        return ans;
    }
}

// int main(void){
//     freopen("input.txt", "r", stdin);
//     int n1, m1, k1;
//     cin>>n1>>m1>>k1;
//     vector<vector<int>> t;
//     t.assign(n1, vector<int>(m1, 0));
//     for(int i = 0; i<n1; i++) for(int j = 0; j<m1; j++) cin>>t[i][j];
//     cout<<find_maximum(k1, t);
// }
#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...