This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<db> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };
#include "tickets.h"
int n,m;
Pi p[1500];
ll d[751][751];
ll go(int i,int j,vector<Vi> &x){
if(i==n/2 && j==n/2)return 0;
ll &ret=d[i][j];
if(ret!=-INF-5)return ret;
ret=-INF;
int N=i+j;
if(i<n/2)ret=max(ret,-x[N][p[N].X]+go(i+1,j,x));
if(j<n/2)ret=max(ret,x[N][p[N].Y]+go(i,j+1,x));
return ret;
}
void track(int i,int j,int k,vector<Vi> &x, vector<Vi> &s){
if(i==n/2 && j==n/2)return;
int N=i+j;
if(i<n/2 && -x[N][p[N].X]+go(i+1,j,x)==go(i,j,x)){
s[N][p[N].X++]=k;
track(i+1,j,k,x,s);
return;
}
if(j<n/2 && x[N][p[N].Y]+go(i,j+1,x)==go(i,j,x)){
s[N][p[N].Y--]=k;
track(i,j+1,k,x,s);
return;
}
}
/*void allocate_tickets(vector<Vi> &s){
int n=s.size(),m=s[0].size();
fup(i,0,n-1,1){
fup(j,0,m-1,1){
printf("%d ",s[i][j]);
}
puts("");
}
}*/
ll find_maximum(int k, vector<Vi> x){
n=x.size(),m=x[0].size();
vector<Vi> s(n,Vi(m,-1));
fup(i,0,n-1,1)p[i].Y=m-1;
ll res=0;
fup(ii,0,k-1,1){
fup(i,0,n/2,1)fup(j,0,n/2,1)d[i][j]=-INF-5;
res+=go(0,0,x);
track(0,0,ii,x,s);
}
allocate_tickets(s);
return res;
}/*
int main() {
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
vector<Vi> x(n,Vi(m));
fup(i,0,n-1,1)fup(j,0,m-1,1)scanf("%d",&x[i][j]);
printf("%lld\n",find_maximum(k,x));
}*/
Compilation message (stderr)
tickets.cpp: In function 'll find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
tickets.cpp:81:2: note: in expansion of macro 'fup'
81 | fup(i,0,n-1,1)p[i].Y=m-1;
| ^~~
tickets.cpp:10:30: warning: unnecessary parentheses in declaration of 'ii' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
tickets.cpp:83:2: note: in expansion of macro 'fup'
83 | fup(ii,0,k-1,1){
| ^~~
tickets.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
tickets.cpp:84:3: note: in expansion of macro 'fup'
84 | fup(i,0,n/2,1)fup(j,0,n/2,1)d[i][j]=-INF-5;
| ^~~
tickets.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
tickets.cpp:84:17: note: in expansion of macro 'fup'
84 | fup(i,0,n/2,1)fup(j,0,n/2,1)d[i][j]=-INF-5;
| ^~~
# | 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... |