This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//by szh
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
#include "tickets.h"
const int maxn = 1555;
int bg[maxn],ed[maxn];
ll f[maxn][maxn];
int lst[maxn][maxn];
long long find_maximum(int k, std::vector<std::vector<int>> x) {
int n = x.size();
int m = x[0].size();
std::vector<std::vector<int>> answer;
for (int i = 0; i < n; i++) {
vector <int> tmp;
bg[i] = 0, ed[i] = m-1;
for (int j = 0; j < m; j++) tmp.pb(-1);
answer.pb(tmp);
}
ll ans = 0;
rep(t,0,k) {
rep(j,0,n+1) rep(i,0,n/2+1) f[j][i] = -1e15;
f[0][0] = 0;
rep(i,0,n) {
rep(j,0,n/2+1) {
if (f[i+1][j] < f[i][j] + x[i][ed[i]]) {
f[i+1][j] = f[i][j] + x[i][ed[i]];
lst[i+1][j] = 0;
}
if (j+1<=n/2 and f[i+1][j+1] < f[i][j] - x[i][bg[i]]) {
f[i+1][j+1] = f[i][j] - x[i][bg[i]];
lst[i+1][j+1] = -1;
}
}
}
ans += f[n][n/2];
// debug(ans);
int curi=n,curj=n/2;
while (curi!=0) {
if (lst[curi][curj]==-1) answer[curi-1][bg[curi-1]++] = t;
else answer[curi-1][ed[curi-1]--] = t;
curj+=lst[curi][curj],curi--;
}
}
allocate_tickets(answer);
return ans;
}
# | 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... |