제출 #1317130

#제출 시각아이디문제언어결과실행 시간메모리
1317130opeleklanos카니발 티켓 (IOI20_tickets)C++20
27 / 100
311 ms104556 KiB
#include <iostream> #include <algorithm> #include <vector> #include "tickets.h" using namespace std; #define ll long long vector<vector<ll>> x; vector<vector<pair<ll, ll>>> dp; ll n, m; pair<ll, ll> makeDp(ll indx, ll 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){ n = x1.size(); m = x1[0].size(); x.assign(n, vector<ll>(m, 0)); for(int i = 0; i<n; i++) for(int j = 0; j<m; j++) x[i][j] = (ll)x1[i][j]; if(m == 1){ sort(x.begin(), x.end()); ll ans = 0; for(ll i = 0; i<n/2; i++) ans -= (ll)x[i][0]; for(ll 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))); ll ans = makeDp(n-1, n/2).first; vector<vector<int>> arr(n, vector<int>(m, -1)); ll uh = n/2; for(ll 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...