답안 #12731

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
12731 2015-01-02T09:41:05 Z ainu7 일도양단! (kriii1_1) C++
0 / 1
0 ms 2700 KB
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;

int R, C, H, N;
int dp[8][8][8][8][8][8];
int P[7][7][7];

int solve(int r1, int c1, int h1, int r2, int c2, int h2, int cnt) {
  if (cnt == 1) return (r2-r1+1)*(c2-c1+1)*(h2-h1+1);
  if (dp[r1][c1][h1][r2][c2][h2]) return dp[r1][c1][h1][r2][c2][h2];

  int res = -999;
  int cnt2 = 0;
  for (int i=r1; i<r2; i++) {
    for (int j=c1; j<=c2; j++)
      for (int k=h1; k<=h2; k++)
        cnt2 += P[i][j][k];
    if (cnt2 == 0 || cnt2 == cnt) continue;
    int now1 = solve(r1, c1, h1, i, c2, h2, cnt2);
    int now2 = solve(i+1, c1, h1, r2, c2, h2, cnt-cnt2);
    res = max(res, min(now1, now2));
  }
  cnt2 = 0;
  for (int i=c1; i<c2; i++) {
    for (int j=r1; j<=r2; j++)
      for (int k=h1; k<=h2; k++)
        cnt2 += P[j][i][k];
    if (cnt2 == 0 || cnt2 == cnt) continue;
    int now1 = solve(r1, c1, h1, r2, i, h2, cnt2);
    int now2 = solve(r1, i+1, h1, r2, c2, h2, cnt-cnt2);
    res = max(res, min(now1, now2));
  }
  cnt2 = 0;
  for (int i=h1; i<h2; i++) {
    for (int j=r1; j<=r2; j++)
      for (int k=c1; k<=c2; k++)
        cnt2 += P[j][k][i];
    if (cnt2 == 0 || cnt2 == cnt) continue;
    int now1 = solve(r1, c1, h1, r1, c2, i, cnt2);
    int now2 = solve(r1, c1, i+1, r2, c2, h2, cnt-cnt2);
    res = max(res, min(now1, now2));
  }

//  printf("%d %d %d - %d %d %d = %d(%d)\n", r1, c1, h1, r2, c2, h2, res, cnt);
  return dp[r1][c1][h1][r2][c2][h2] = res;
}

int main()
{
  cin >> R >> C >> H >> N;
  for (int i=0; i<N; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    P[a-1][b-1][c-1] = 1;
  }

  cout << solve(0, 0, 0, R-1, C-1, H-1, N) << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2700 KB Output is correct
2 Correct 0 ms 2700 KB Output is correct
3 Correct 0 ms 2700 KB Output is correct
4 Incorrect 0 ms 2700 KB Output isn't correct
5 Halted 0 ms 0 KB -