Submission #3336

#TimeUsernameProblemLanguageResultExecution timeMemory
3336wookayin일도양단! (kriii1_1)C++98
1 / 1
4 ms2132 KiB
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;

int R, C, H, N;
int has[7][7][7];

struct xyz {
        int x, y, z;
        xyz(int x, int y, int z) : x(x), y(y), z(z) {}
};
vector<xyz> pos;

int count(int r1, int r2, int c1, int c2, int h1, int h2) {
        int s = 0;
        for(int i = 0; i < pos.size(); ++ i) {
                xyz &q = pos[i];
                if(r1 <= q.x && q.x <= r2 && c1 <= q.y && q.y <= c2 && h1 <= q.z && q.z <= h2)
                        s ++;
        }
        return s;
}

int cache[7][7][7][7][7][7];
int go(int r1, int r2, int c1, int c2, int h1, int h2) {
        int &ret = cache[r1][r2][c1][c2][h1][h2];
        if(ret != -1) return ret;

        // 건빵이 하나 들어있으면
        int raisins = count(r1, r2, c1, c2, h1, h2);
        if(raisins == 1)
                return ret = (r2-r1+1) * (c2-c1+1) * (h2-h1+1);

        ret = -987987987;
        for(int r = r1; r < r2; ++ r) {
                int t1 = go(r1, r, c1, c2, h1, h2);
                int t2 = go(r+1, r2, c1, c2, h1, h2);
                int tv = min(t1, t2);
                ret = max(ret, tv);
        }
        for(int c = c1; c < c2; ++ c) {
                int t1 = go(r1, r2, c1, c, h1, h2);
                int t2 = go(r1, r2, c+1, c2, h1, h2);
                int tv = min(t1, t2);
                ret = max(ret, tv);
        }
        for(int h = h1; h < h2; ++ h) {
                int t1 = go(r1, r2, c1, c2, h1, h);
                int t2 = go(r1, r2, c1, c2, h+1, h2);
                int tv = min(t1, t2);
                ret = max(ret, tv);
        }
        return ret;
}

int main() {
        cin >> R >> C >> H >> N;
        for(int i = 0; i < N; ++ i) {
                int r, c, h;
                cin >> r >> c >> h;
                r--; c--; h--;
                pos.push_back( xyz(r,c,h) );
                has[r][c][h] = 1;
        }
        memset(cache, -1, sizeof(cache));
        int res = go(0, R-1, 0, C-1, 0, H-1);
        printf("%d\n", res);
        return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...