結果

問題 No.1045 直方体大学
ユーザー tarattata1tarattata1
提出日時 2020-05-01 23:22:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,562 bytes
コンパイル時間 637 ms
コンパイル使用メモリ 82,104 KB
実行使用メモリ 27,604 KB
最終ジャッジ日時 2023-08-26 15:51:53
合計ジャッジ時間 1,797 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 37 ms
27,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <cassert>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

ll dp[1 << 16][16][3];

void solve()
{
    int n;
    scanf("%d", &n);
    vector<int> a(n * 3);
    int i,j,k;
    for (i = 0; i < n; i++) {
        scanf("%d%d%d", &a[3*i], &a[3*i+1], &a[3*i+2]);
    }

    for (i = 0; i < (1 << n); i++) {
        for (j = 0; j < n; j++) {
            for (k = 0; k < 3; k++) {
                dp[i][j][k] = -1;
            }
        }
    }

    ll ans = 0;
    for (j = 0; j < n; j++) {
        for (k = 0; k < 3; k++) {
            dp[1 << j][j][k] = a[3 * j + k];
            ans = MAX(ans, dp[1 << j][j][k]);
        }
    }

    for (i = 0; i < (1 << n); i++) {
        for (j = 0; j < n; j++) {
            for (k = 0; k < 3; k++) {
                if (dp[i][j][k] >= 0) {
                    int p;
                    for (p = 0; p < n; p++) {
                        if (i & (1 << p)) continue;

                        int k2;
                        for (k2 = 0; k2 < 3; k2++) {
                            int k_1 = (k + 1) % 3, k_2 = (k + 2) % 3;
                            int k2_1 = (k2 + 1) % 3, k2_2 = (k2 + 2) % 3;
                            if (MIN(3 * j + k_1, 3 * j + k_2) <= MIN(3 * p + k2_1, 3 * p + k2_2)) {
                                if (MAX(3 * j + k_1, 3 * j + k_2) <= MAX(3 * p + k2_1, 3 * p + k2_2)) {
                                    dp[i | (1 << p)][p][k2] = dp[i][j][k] + a[3 * p + k2];
                                    ans = MAX(ans, dp[i | (1 << p)][p][k2]);
                                }
                            }                            
                        }
                    }
                }
            }
        }
    }
    printf("%lld\n", ans);

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}

0