結果

問題 No.519 アイドルユニット
ユーザー snrnsidysnrnsidy
提出日時 2021-06-12 02:43:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 761 ms / 1,000 ms
コード長 718 bytes
コンパイル時間 1,941 ms
コンパイル使用メモリ 198,824 KB
実行使用メモリ 69,188 KB
最終ジャッジ日時 2023-08-21 17:43:25
合計ジャッジ時間 9,545 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 757 ms
68,952 KB
testcase_01 AC 759 ms
69,024 KB
testcase_02 AC 195 ms
68,888 KB
testcase_03 AC 28 ms
68,956 KB
testcase_04 AC 19 ms
69,052 KB
testcase_05 AC 19 ms
68,908 KB
testcase_06 AC 19 ms
69,084 KB
testcase_07 AC 19 ms
68,892 KB
testcase_08 AC 19 ms
68,980 KB
testcase_09 AC 19 ms
68,880 KB
testcase_10 AC 21 ms
68,972 KB
testcase_11 AC 28 ms
68,968 KB
testcase_12 AC 19 ms
68,948 KB
testcase_13 AC 29 ms
68,916 KB
testcase_14 AC 29 ms
69,092 KB
testcase_15 AC 29 ms
68,932 KB
testcase_16 AC 28 ms
68,912 KB
testcase_17 AC 28 ms
68,944 KB
testcase_18 AC 28 ms
68,916 KB
testcase_19 AC 28 ms
68,944 KB
testcase_20 AC 28 ms
68,952 KB
testcase_21 AC 28 ms
69,088 KB
testcase_22 AC 29 ms
68,900 KB
testcase_23 AC 28 ms
68,916 KB
testcase_24 AC 60 ms
69,036 KB
testcase_25 AC 59 ms
68,880 KB
testcase_26 AC 60 ms
68,900 KB
testcase_27 AC 60 ms
68,920 KB
testcase_28 AC 60 ms
68,916 KB
testcase_29 AC 759 ms
68,944 KB
testcase_30 AC 761 ms
68,932 KB
testcase_31 AC 755 ms
69,188 KB
testcase_32 AC 758 ms
69,020 KB
testcase_33 AC 18 ms
68,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int board[25][25];
int dp[1 << 24];

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin >> board[i][j];
		}
	}
	memset(dp, -1, sizeof(dp));
	dp[0] = 0;

	for (int i = 0; i < (1 << n); i++)
	{
		if (__builtin_popcount(i) % 2 == 1) continue;
		for (int j = 0; j < n; j++)
		{
			if ((i & (1 << j)) == 0)
			{
				for (int k = j + 1; k < n; k++)
				{
					if ((i & (1 << k)) == 0)
					{
						int mask = i + (1 << j) + (1 << k);
						dp[mask] = max(dp[mask], dp[i] + board[j][k]);
					}
				}
				break;
			}
		}
	}

	cout << dp[(1 << n) - 1] << '\n';

	return 0;
}
0