1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| const ll inf = 1ll<<60; const int maxn = 20 + 10; ll S[maxn][maxn][maxn]; int a, b, c;
inline void expand(int i, int &b0, int &b1, int &b2) { b0 = i&1; i >>= 1; b1 = i&1; i >>= 1; b2 = i&1; }
inline int sgn(int b0, int b1, int b2) { return (b0 + b1 + b2) % 2 == 1 ? 1 : -1; }
ll sum(int x1, int x2, int y1, int y2, int z1, int z2) { int dx = x2-x1+1, dy = y2-y1+1, dz = z2-z1+1;
ll ans = 0; _rep(i, 0, 7) { int b0, b1, b2; expand(i, b0, b1, b2); ans -= S[x2-b0*dx][y2-b1*dy][z2-b2*dz] * sgn(b0, b1, b2); } return ans; }
void prework() { _rep(x, 1, a) _rep(y, 1, b) _rep(z, 1, c) _rep(i, 1, 7) { int b0, b1, b2; expand(i, b0, b1, b2); S[x][y][z] += S[x-b0][y-b1][z-b2] * sgn(b0, b1, b2); } }
void solve() { ll ans = -inf; _rep(x1, 1, a) _rep(x2, x1, a) _rep(y1, 1, b) _rep(y2, y1, b) { ll M = 0; _rep(z, 1, c) { ll s = sum(x1, x2, y1, y2, 1, z); chmax(ans, s - M); chmin(M, s); } } printf("%lld\n", ans); }
void init() { memset(S, 0, sizeof(S)); }
int main() { freopen("input.txt", "r", stdin); int kase; cin >> kase;
while (kase--) { scanf("%d%d%d", &a, &b, &c); init();
// get data _rep(x, 1, a) _rep(y, 1, b) _rep(z, 1, c) scanf("%lld", &S[x][y][z]);
// then prework and solve prework(); solve(); if (kase) printf("\n"); } }
|