結果

問題 No.1045 直方体大学
ユーザー tsutajtsutaj
提出日時 2020-05-01 22:33:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 466 ms / 2,000 ms
コード長 2,480 bytes
コンパイル時間 1,153 ms
コンパイル使用メモリ 106,188 KB
実行使用メモリ 28,372 KB
最終ジャッジ日時 2023-08-26 15:13:54
合計ジャッジ時間 2,805 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 35 ms
28,060 KB
testcase_09 AC 29 ms
28,108 KB
testcase_10 AC 21 ms
28,104 KB
testcase_11 AC 28 ms
28,080 KB
testcase_12 AC 36 ms
28,236 KB
testcase_13 AC 74 ms
28,108 KB
testcase_14 AC 37 ms
28,372 KB
testcase_15 AC 65 ms
28,168 KB
testcase_16 AC 69 ms
28,360 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 466 ms
28,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

const int K = 6;
int dp[1 << 16][16][K];
int main() {
    int N; scanf("%d", &N);
    vector< vector<int> > L(N, vector<int>(3));
    for(int i=0; i<N; i++) {
        for(int j=0; j<3; j++) scanf("%d", &L[i][j]);
    }

    // AB, AC, BA, BC, CA, CB
    vector< vector<int> > dir(K);
    dir[0] = {0, 1};
    dir[1] = {0, 2};
    dir[2] = {1, 0};
    dir[3] = {1, 2};
    dir[4] = {2, 0};
    dir[5] = {2, 1};

    fill(dp[0][0], dp[1<<N][0], -1);

    int ans = 0;
    for(int i=0; i<N; i++) {
        for(int j=0; j<K; j++) {
            int z = 3 ^ dir[j][0] ^ dir[j][1];
            dp[1 << i][i][j] = L[i][z];
            chmax(ans, dp[1 << i][i][j]);
        }
    }

    for(int bit=0; bit<(1<<N); bit++) {
        for(int i=0; i<N; i++) {
            for(int j=0; j<K; j++) {
                if(dp[bit][i][j] < 0) continue;
                int h0 = L[i][ dir[j][0] ], w0 = L[i][ dir[j][1] ];
                for(int k=0; k<N; k++) {
                    if(bit >> k & 1) continue;
                    int nbit = bit | (1 << k);
                    for(int x=0; x<K; x++) {
                        int z = 3 ^ dir[x][0] ^ dir[x][1];
                        int h1 = L[k][ dir[x][0] ], w1 = L[k][ dir[x][1] ];
                        int o1 = L[k][z];
                        if(h0 >= h1 and w0 >= w1) {
                            chmax(dp[nbit][k][x], dp[bit][i][j] + o1);
                            chmax(ans, dp[bit][i][j] + o1);
                        }
                    }
                }
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}
0