結果

問題 No.90 品物の並び替え
ユーザー masamasa
提出日時 2015-02-26 20:19:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 13 ms / 5,000 ms
コード長 660 bytes
コンパイル時間 868 ms
コンパイル使用メモリ 67,692 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 05:07:55
合計ジャッジ時間 1,787 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 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 1 ms
4,376 KB
testcase_09 AC 13 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int main() {
	int n, m;
	int a, b, c;

	cin >> n >> m;
	vector< vector<int> > score(n, vector<int>(n, 0));
	for (int i = 0; i < m; i++) {
		cin >> a >> b >> c;
		score[a][b] = c;
	}

	vector<int> order(n, 0);
	for (int i = 0; i < n; i++) {
		order[i] = i;
	}

	int ans = 0;
	int total;
	do {
		total = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				total += score[order[i]][order[j]];
			}
		}
		ans = max(ans, total);
	} while (next_permutation(order.begin(), order.end()));

	cout << ans << endl;
	return 0;
}
0