結果

問題 No.1045 直方体大学
ユーザー Plan8Plan8
提出日時 2020-05-09 13:59:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 228 ms / 2,000 ms
コード長 2,759 bytes
コンパイル時間 2,299 ms
コンパイル使用メモリ 205,464 KB
実行使用メモリ 15,824 KB
最終ジャッジ日時 2023-09-19 05:45:46
合計ジャッジ時間 6,119 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 189 ms
15,628 KB
testcase_09 AC 186 ms
15,696 KB
testcase_10 AC 181 ms
15,640 KB
testcase_11 AC 185 ms
15,824 KB
testcase_12 AC 191 ms
15,656 KB
testcase_13 AC 190 ms
15,696 KB
testcase_14 AC 191 ms
15,744 KB
testcase_15 AC 193 ms
15,824 KB
testcase_16 AC 197 ms
15,728 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 228 ms
15,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int N;
int dp[1<<16][16][3];
VVI a(16,VI(3));
int ans = 0;

int rec(int S, int u, int v, int n){
    if(dp[S][u][v] != -1) return dp[S][u][v];
    if(n == 1){
        REP(i,N){
            if(!(S & 1<<i)) continue;
            chmax(ans, a[i][v]);
            return dp[S][u][v] = a[i][v];
        }
    }

    int x,y;
    if(v == 0){
        x = a[u][1]; y = a[u][2];
    }
    else if(v == 1){
        x = a[u][0]; y = a[u][2];
    }
    else{
        x = a[u][0]; y = a[u][1];
    }

    int ret = -1000000000;
    int prev = S ^ (1<<u);
    REP(i,N){
        if(!(prev & 1<<i)) continue;
        REP(j,3){
            int t = rec(prev, i, j, n-1);
            if(t < 0) continue;
            int p,q;
            if(j == 0){
                p = a[i][1]; q = a[i][2];
            }
            else if(j == 1){
                p = a[i][0]; q = a[i][2];
            }
            else{
                p = a[i][0]; q = a[i][1];
            }
            if(p < x || q < y) continue;
            chmax(ret, t + a[u][v]);
        }
    }
    chmax(ans, ret);
    return dp[S][u][v] = ret;
}

int main(void){
    cin >> N; REP(i,N)REP(j,3) cin >> a[i][j];
    REP(i,N) SORT(a[i]);
    REP(i,1<<N)REP(j,N)REP(k,3) dp[i][j][k] = -1;

    REP(i,N)REP(j,3) rec((1<<N)-1, i, j, N);
    cout << ans << endl;
    return 0;
}
0