結果

問題 No.90 品物の並び替え
ユーザー nominomi
提出日時 2019-03-11 22:24:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 5,000 ms
コード長 667 bytes
コンパイル時間 1,917 ms
コンパイル使用メモリ 167,952 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 20:16:54
合計ジャッジ時間 2,089 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }

int N, M;
int item[100][100]; // item1, item2, scoreをこれひとつにまとめた

signed main() {
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		item[a][b] = c;
	}

	vector<int> v(N);
	iota(v.begin(), v.end(), 0);

	int ans = 0;
	do {
		int sum = 0;

		for (int i = 0; i < N; i++) {
			for (int j = i+1; j < N; j++) {
				sum += item[v[i]][v[j]];
			}
		}

		chmax(ans, sum);
	} while (next_permutation(v.begin(), v.end()));

	cout << ans << endl;

  return 0;
}
0