結果

問題 No.1045 直方体大学
ユーザー 沙耶花沙耶花
提出日時 2020-05-01 22:51:53
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 1,352 bytes
コンパイル時間 2,072 ms
コンパイル使用メモリ 209,480 KB
実行使用メモリ 18,292 KB
最終ジャッジ日時 2023-08-26 15:34:32
合計ジャッジ時間 3,377 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 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,376 KB
testcase_08 AC 34 ms
18,044 KB
testcase_09 AC 28 ms
18,100 KB
testcase_10 AC 28 ms
18,108 KB
testcase_11 AC 27 ms
18,072 KB
testcase_12 AC 37 ms
18,044 KB
testcase_13 AC 35 ms
18,060 KB
testcase_14 AC 30 ms
18,140 KB
testcase_15 AC 42 ms
18,292 KB
testcase_16 AC 54 ms
18,076 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 185 ms
18,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000


int main(){
	
	int N;
	cin>>N;
	
	vector<pair<pair<int,int>,int>> V(N*3); 
	
	for(int i=0;i<N;i++){
		vector<int> v(3);
		cin>>v[0]>>v[1]>>v[2];
		sort(v.begin(),v.end());
		V[i*3] = make_pair(make_pair(v[0],v[1]),v[2]);
		V[i*3+1] = make_pair(make_pair(v[0],v[2]),v[1]);
		V[i*3+2] =  make_pair(make_pair(v[1],v[2]),v[0]);
	}
		
	vector<vector<int>> ind(N+1,vector<int>());
	for(int i=0;i<(1<<N);i++){
		int c = 0;
		for(int j=0;j<N;j++){
			if((i>>j)&1)c++;
		}
		ind[c].push_back(i);
	}
	
	
	vector<vector<int>> dp(1<<N,vector<int>(N*3,-Inf));
	dp[0][0] = 0;

	for(int i=0;i<N;i++){
		for(int j=0;j<ind[i].size();j++){
			int m = ind[i][j];
			for(int k=0;k<3*N;k++){
				if(dp[m][k]==-Inf)continue;
				for(int l=0;l<3*N;l++){
					int nm = m|(1<<(l/3));
					if(m==nm)continue;
					if(i!=0&&(V[k].first.first>V[l].first.first||V[k].first.second>V[l].first.second))continue;
					dp[nm][l] = max(dp[nm][l],dp[m][k] + V[l].second);
				}
			}
		}
	}
	/*
	for(int i=0;i<(1<<N);i++){
		for(int j=0;j<3*N;j++){
			cout<<dp[i][j]<<',';
		}
		cout<<endl;
	}
	*/
	int ans = 0;
	for(int i=0;i<(1<<N);i++){
		for(int j=0;j<3*N;j++){
			ans = max(ans,dp[i][j]);
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}
0