結果

問題 No.90 品物の並び替え
ユーザー data9824data9824
提出日時 2015-06-02 16:24:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 106 ms / 5,000 ms
コード長 611 bytes
コンパイル時間 504 ms
コンパイル使用メモリ 64,032 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 18:49:53
合計ジャッジ時間 1,316 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> item1(m), item2(m), score(m);
	for (int i = 0; i < m; ++i) {
		cin >> item1[i] >> item2[i] >> score[i];
	}
	int maxScore = 0;
	vector<int> positions(n);
	for (int i = 0; i < n; ++i) {
		positions[i] = i;
	}
	do {
		int s = 0;
		for (int k = 0; k < m; ++k) {
			if (positions[item1[k]] < positions[item2[k]]) {
				s += score[k];
			}
		}
		maxScore = max(maxScore, s);
	} while (next_permutation(&positions[0], &positions[n - 1] + 1));
	cout << maxScore << endl;
	return 0;
}
0