結果

問題 No.90 品物の並び替え
ユーザー GoryudyumaGoryudyuma
提出日時 2015-04-21 12:51:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 709 bytes
コンパイル時間 620 ms
コンパイル使用メモリ 67,916 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 02:17:41
合計ジャッジ時間 1,307 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 12 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;


int main()
{
	int N, M;
	cin >> N >> M;
	vector<vector<int>>data;
	vector<int>data2;
	data.resize(N);
	data2.resize(N);
	for (size_t i = 0; i < N; i++)
	{
		data[i].resize(N);
		for (size_t j = 0; j < N; j++)
		{
			data[i][j] = 0;
		}
		data2[i] = i;
	}
	int a, b, c;
	for (size_t i = 0; i < M; i++)
	{
		cin >> a >> b >> c;
		data[a][b] = c;
	}
	int ans = 0;
	do
	{
		int max_ = 0;
		for (size_t i = 0; i < N-1; i++)
		{
			for (size_t j = i+1; j < N; j++)
			{
				max_ += data[data2[i]][data2[j]];
			}
		}
		ans = max(ans, max_);
	} while (next_permutation(data2.begin(), data2.end()));
	cout << ans << endl;
	return 0;
}
0