結果

問題 No.519 アイドルユニット
ユーザー 👑 rin204rin204
提出日時 2022-11-08 18:57:20
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 968 bytes
コンパイル時間 4,373 ms
コンパイル使用メモリ 267,736 KB
実行使用メモリ 68,572 KB
最終ジャッジ日時 2023-09-29 08:26:18
合計ジャッジ時間 13,822 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 AC 277 ms
19,512 KB
testcase_03 AC 18 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 18 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 18 ms
4,376 KB
testcase_14 AC 18 ms
4,376 KB
testcase_15 AC 18 ms
4,380 KB
testcase_16 AC 18 ms
4,376 KB
testcase_17 AC 18 ms
4,376 KB
testcase_18 AC 18 ms
4,380 KB
testcase_19 AC 19 ms
4,380 KB
testcase_20 AC 18 ms
4,376 KB
testcase_21 AC 18 ms
4,380 KB
testcase_22 AC 18 ms
4,376 KB
testcase_23 AC 17 ms
4,376 KB
testcase_24 AC 68 ms
7,144 KB
testcase_25 AC 69 ms
7,084 KB
testcase_26 AC 67 ms
7,196 KB
testcase_27 AC 69 ms
7,100 KB
testcase_28 AC 69 ms
7,152 KB
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
// #include<atcoder/scc>
using namespace std;
// using namespace atcoder;


void chmax(int &a, int b){
	if(a < b) a = b;
}

void solve(){    
	int n;
	cin >> n;
	vector<vector<int>> F(n, vector<int>(n, 0));
	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> F[i][j];
	vector<int> dp(1 << n, 0);
	for(int bit = 0; bit < (1 << n - 1) - 1; bit++){
		int pc = 1;
		int ii = -1;
		for(int i = 0; i < n - 1; i++){
			if(bit >> i & 1);
			else if(ii == -1){
				ii = i;
				pc ^= 1;
			}
			else{
				pc ^= 1;
			}
		}
		int S = bit | (pc << (n - 1));		
		for(int i = ii + 1; i < n; i++){
			if(S >> i & 1);
			else{
				int nbit = S | (1 << i) | (1 << ii);
				chmax(dp[nbit], dp[S] + F[i][ii]);
			}
		}	
	}
	cout << dp[(1 << n) - 1] << "\n";
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
	int t;
	t = 1;
	// cin >> t;
	while(t--) solve();
}
	
	
0