This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Author: Kajetan Ramsza
#include "bits/stdc++.h"
#include "tickets.h"
using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename F, typename S> ostream& operator<<(ostream& os, const pair<F, S> &p) { return os<<"("<<p.first<<", "<<p.second<<")"; }
template<typename T> ostream &operator<<(ostream & os, const vector<T> &v) { os << "{"; typename vector< T > :: const_iterator it;
for( it = v.begin(); it != v.end(); it++ ) { if( it != v.begin() ) os << ", "; os << *it; } return os << "}"; }
void dbg_out() { cerr<<'\n'; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr<<' '<<H; dbg_out(T...); }
#ifdef DEBUG
#define dbg(...) cerr<<"(" << #__VA_ARGS__ <<"):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
const ll inf = ll(1e18) + 7;
int n, m, k;
vector<vi> answer;
vector<pii> used;
vector<vector<ll>> tickets;
void update_used(vector<vector<ll>> &dp, int ind) {
int curr = n / 2;
for(int i=n-1;i>=0;i--) {
if(dp[i+1][curr] == dp[i][curr] + tickets[i][used[i].second]) {
answer[i][used[i].second] = ind;
used[i].second--;
} else {
answer[i][used[i].first] = ind;
used[i].first++;
curr--;
}
}
}
ll solve() {
used.assign(n, {0, m-1});
vector<vector<ll>> dp(n+1, vector<ll>(n+1, -inf));
dp[0][0] = 0;
ll result = 0;
rep(ind,0,k) {
rep(i,0,n) {
dp[i+1][0] = -inf;
rep(j,0,i+1) {
dp[i+1][j] = max(dp[i+1][j], dp[i][j] + tickets[i][used[i].second]);
dp[i+1][j+1] = dp[i][j] - tickets[i][used[i].first];
}
}
dbg(used);
dbg(dp);
update_used(dp, ind);
result += dp[n][n / 2];
}
return result;
}
ll find_maximum(int k_, vector<vi> tickets_) {
k = k_;
n = tickets_.size();
m = tickets_[0].size();
tickets.assign(n, vector<ll>(m));
rep(i,0,n) rep(j,0,m) tickets[i][j] = tickets_[i][j];
answer.assign(n, vi(m, -1));
ll res = solve();
allocate_tickets(answer);
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |