結果

問題 No.1045 直方体大学
ユーザー 👑 kmjpkmjp
提出日時 2020-05-01 22:19:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 524 ms / 2,000 ms
コード長 1,369 bytes
コンパイル時間 2,096 ms
コンパイル使用メモリ 199,888 KB
実行使用メモリ 40,496 KB
最終ジャッジ日時 2023-08-26 14:47:49
合計ジャッジ時間 4,204 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
40,232 KB
testcase_01 AC 12 ms
40,324 KB
testcase_02 AC 12 ms
40,240 KB
testcase_03 AC 12 ms
40,240 KB
testcase_04 AC 12 ms
40,236 KB
testcase_05 AC 13 ms
40,396 KB
testcase_06 AC 12 ms
40,228 KB
testcase_07 AC 12 ms
40,228 KB
testcase_08 AC 51 ms
40,240 KB
testcase_09 AC 43 ms
40,312 KB
testcase_10 AC 34 ms
40,396 KB
testcase_11 AC 41 ms
40,240 KB
testcase_12 AC 51 ms
40,476 KB
testcase_13 AC 97 ms
40,228 KB
testcase_14 AC 51 ms
40,236 KB
testcase_15 AC 81 ms
40,236 KB
testcase_16 AC 89 ms
40,496 KB
testcase_17 AC 13 ms
40,236 KB
testcase_18 AC 524 ms
40,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int X[16][3];
int ma[1<<16][16][3][3];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	MINUS(ma);
	cin>>N;
	FOR(i,N) {
		cin>>X[i][0]>>X[i][1]>>X[i][2];
		FOR(x,3) FOR(y,3) if(x!=y) ma[1<<i][i][x][y]=X[i][3-x-y];
	}
	
	int ret=0;
	for(int mask=0;mask<1<<N;mask++) FOR(i,N) if(mask&(1<<i)) {
		FOR(x,3) FOR(y,3) if(x!=y && ma[mask][i][x][y]>=0) {
			ret=max(ret,ma[mask][i][x][y]);
			
			FOR(j,N) if((mask&(1<<j))==0) {
				int x2,y2;
				FOR(x2,3) FOR(y2,3) if(x2!=y2) {
					if(X[j][x2]>X[i][x]) continue;
					if(X[j][y2]>X[i][y]) continue;
					ma[mask|(1<<j)][j][x2][y2]=max(ma[mask|(1<<j)][j][x2][y2],ma[mask][i][x][y]+X[j][3-x2-y2]);
				}
			}
			
		}
	}
	
	cout<<ret<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0