結果

問題 No.1045 直方体大学
ユーザー furafura
提出日時 2020-07-31 12:06:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 914 bytes
コンパイル時間 4,302 ms
コンパイル使用メモリ 201,436 KB
実行使用メモリ 16,000 KB
最終ジャッジ日時 2023-09-20 08:03:51
合計ジャッジ時間 5,044 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
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 235 ms
15,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n),b(n),c(n);
	rep(i,n) scanf("%d%d%d",&a[i],&b[i],&c[i]);

	static int dp[1<<16][16][3];
	rep(i,n){
		dp[1<<i][i][0]=c[i];
		dp[1<<i][i][1]=a[i];
		dp[1<<i][i][2]=b[i];
	}
	rep(S,1<<n) rep(i,n) rep(j,3) if(dp[S][i][j]>0) {
		int x,y;
		if     (j==0) x=a[i], y=b[i];
		else if(j==1) x=b[i], y=c[i];
		else          x=c[i], y=a[i];
		if(x>y) swap(x,y);

		rep(i2,n) if((S>>i2&1)==0) rep(j2,3) {
			int x2,y2,z2;
			if     (j==0) x2=a[i2], y2=b[i2], z2=c[i2];
			else if(j==1) x2=b[i2], y2=c[i2], z2=a[i2];
			else          x2=c[i2], y2=a[i2], z2=b[i2];
			if(x2>y2) swap(x2,y2);

			if(x2<=x && y2<=y) dp[S|1<<i2][i2][j2]=max(dp[S|1<<i2][i2][j2],dp[S][i][j]+z2);
		}
	}

	int ans=0;
	rep(S,1<<n) rep(i,n) rep(j,3) ans=max(ans,dp[S][i][j]);
	printf("%d\n",ans);

	return 0;
}
0