結果

問題 No.1045 直方体大学
ユーザー furafura
提出日時 2020-07-31 12:15:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 198 ms / 2,000 ms
コード長 940 bytes
コンパイル時間 2,025 ms
コンパイル使用メモリ 203,080 KB
実行使用メモリ 15,812 KB
最終ジャッジ日時 2023-09-20 08:17:29
合計ジャッジ時間 3,451 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 22 ms
12,428 KB
testcase_09 AC 20 ms
12,716 KB
testcase_10 AC 15 ms
11,488 KB
testcase_11 AC 18 ms
11,740 KB
testcase_12 AC 26 ms
15,752 KB
testcase_13 AC 42 ms
15,752 KB
testcase_14 AC 22 ms
12,664 KB
testcase_15 AC 36 ms
15,196 KB
testcase_16 AC 40 ms
15,788 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 198 ms
15,812 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) tie(x,y)=minmax(a[i],b[i]);
		else if(j==1) tie(x,y)=minmax(b[i],c[i]);
		else          tie(x,y)=minmax(c[i],a[i]);
		rep(i2,n) if((S>>i2&1)==0) rep(j2,3) {
			int x2,y2,z2;
			if     (j2==0) tie(x2,y2)=minmax(a[i2],b[i2]), z2=c[i2];
			else if(j2==1) tie(x2,y2)=minmax(b[i2],c[i2]), z2=a[i2];
			else           tie(x2,y2)=minmax(c[i2],a[i2]), z2=b[i2];
			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