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,kk;
/*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("");
}
}*/
Pi p[80];
int cnt[80];
ll d[80][3201];
ll go(int N,int M,vector<Vi> &x){
if(M>n*kk/2)return -INF;
if(N==n){
if(M==n*kk/2)return 0;
return -INF;
}
ll &ret=d[N][M];
if(ret!=-INF-5)return ret;
ret=-INF;
ll s=0;
fup(i,0,kk-1,1)s+=x[N][m-1-i];
ret=max(ret,s+go(N+1,M,x));
fup(i,0,kk-1,1){
s-=x[N][i]+x[N][m-kk+i];
ret=max(ret,s+go(N+1,M+i+1,x));
}
return ret;
}
void track(int N,int M,vector<Vi> &x){
if(N==n)return;
ll s=0;
fup(i,0,kk-1,1)s+=x[N][m-1-i];
if(go(N,M,x)==s+go(N+1,M,x)){
p[N].Y=m-kk;
track(N+1,M,x);
return;
}
fup(i,0,kk-1,1){
s-=x[N][i]+x[N][m-kk+i];
if(go(N,M,x)==s+go(N+1,M+i+1,x)){
cnt[N]=i+1;
p[N].Y=m-kk+i+1;
track(N+1,M+i+1,x);
return;
}
}
}
ll find_maximum(int k, vector<Vi> x){
kk=k,n=x.size(),m=x[0].size();
fup(i,0,79,1)fup(j,0,3200,1)d[i][j]=-INF-5;
vector<Vi> s(n,Vi(m,-1));
ll res=go(0,0,x);
track(0,0,x);
fup(K,0,k-1,1){
VPi vv(n);
fup(i,0,n-1,1)vv[i]=mp(cnt[i],i);
sort(ALL(vv));
fup(i,0,n/2-1,1){
int ii=vv[i].Y;
s[ii][p[ii].Y++]=K;
}
fup(i,n/2,n-1,1){
int ii=vv[i].Y;
s[ii][p[ii].X++]=K;
cnt[ii]--;
}
}
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 go(int, 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:65:2: note: in expansion of macro 'fup'
65 | fup(i,0,kk-1,1)s+=x[N][m-1-i];
| ^~~
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:67:2: note: in expansion of macro 'fup'
67 | fup(i,0,kk-1,1){
| ^~~
tickets.cpp: In function 'void track(int, 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:76:2: note: in expansion of macro 'fup'
76 | fup(i,0,kk-1,1)s+=x[N][m-1-i];
| ^~~
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:82:2: note: in expansion of macro 'fup'
82 | fup(i,0,kk-1,1){
| ^~~
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:94:2: note: in expansion of macro 'fup'
94 | fup(i,0,79,1)fup(j,0,3200,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:94:15: note: in expansion of macro 'fup'
94 | fup(i,0,79,1)fup(j,0,3200,1)d[i][j]=-INF-5;
| ^~~
tickets.cpp:10:30: warning: unnecessary parentheses in declaration of 'K' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
tickets.cpp:98:2: note: in expansion of macro 'fup'
98 | fup(K,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:100:3: note: in expansion of macro 'fup'
100 | fup(i,0,n-1,1)vv[i]=mp(cnt[i],i);
| ^~~
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:102:3: note: in expansion of macro 'fup'
102 | fup(i,0,n/2-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:106:3: note: in expansion of macro 'fup'
106 | fup(i,n/2,n-1,1){
| ^~~
# | 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... |