제출 #19540

#제출 시각아이디문제언어결과실행 시간메모리
19540gs14004일도양단! (kriii1_1)C++14
0 / 1
0 ms16384 KiB
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <limits.h> #include <stack> #include <queue> #include <map> #include <set> #include <algorithm> #include <string> #include <functional> #include <vector> #include <numeric> #include <deque> #include <utility> #include <bitset> #include <iostream> using namespace std; typedef long long lint; typedef long double llf; typedef pair<int, int> pi; int a[8][8][8]; int dp[8][8][8][8][8][8][78]; int getsum(int sx, int ex, int sy, int ey, int sz, int ez){ return a[ex][ey][ez] - a[sx-1][ey][ez] - a[ex][sy-1][ez] - a[ex][ey][sz-1] + a[sx-1][sy-1][ez] + a[sx-1][ey][sz-1] + a[ex][sy-1][sz-1] - a[sx-1][sy-1][sz-1]; } int f(int sx, int ex, int sy, int ey, int sz, int ez, int k){ if(getsum(sx, ex, sy, ey, sz, ez) != k) return -1e9; if(dp[sx][ex][sy][ey][sz][ez][k]) return dp[sx][ex][sy][ey][sz][ez][k]; if(k == 1) return (ex - sx + 1) * (ey - sy + 1) * (ez - sz + 1); int ret = 0; for(int j=1; j<k; j++){ for(int i=sx; i<ex; i++){ ret = max(ret, min(f(sx, i, sy, ey, sz, ez, j), f(i+1, ex, sy, ey, sz, ez, k-j))); } for(int i=sy; i<ey; i++){ ret = max(ret, min(f(sx, ex, sy, i, sz, ez, j), f(sx, ex, i+1, ey, sz, ez, k-j))); } for(int i=sz; i<ez; i++){ ret = max(ret, min(f(sx, ex, sy, ey, sz, i, j), f(sx, ex, sy, ey, i+1, ez, k-j))); } } return dp[sx][ex][sy][ey][sz][ez][k] = ret; } int main(){ int x, y, z, n; cin >> x >> y >> z >> n; for(int i=0; i<n; i++){ int p, q, r; cin >> p >> q >> r; a[p][q][r]++; } for(int i=1; i<=x; i++){ for(int j=1; j<=y; j++){ for(int k=1; k<=z; k++){ a[i][j][k] += a[i-1][j][k] + a[i][j-1][k] + a[i][j][k-1] - a[i-1][j-1][k] - a[i-1][j][k-1] - a[i][j-1][k-1] + a[i-1][j-1][k-1]; } } } cout << f(1, x, 1, y, 1, z, n); }
#Verdict Execution timeMemoryGrader output
Fetching results...