답안 #19539

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
19539 2016-02-24T16:50:56 Z gs14004 일도양단! (kriii1_1) C++14
0 / 1
100 ms 1720 KB
#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 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(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 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);
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 100 ms 1720 KB Program timed out
2 Halted 0 ms 0 KB -