結果

問題 No.90 品物の並び替え
ユーザー yuma220284yuma220284
提出日時 2019-08-10 12:36:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 97 ms / 5,000 ms
コード長 618 bytes
コンパイル時間 2,005 ms
コンパイル使用メモリ 147,176 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 23:20:40
合計ジャッジ時間 3,292 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

struct item {
	int before;
	int after;
	long long score;
};

int main() {
	int N, M;
	long long ANS = 0;
	vector<int> V;
	item X[100];
	cin >> N >> M;
	for (int i = 0; i < N; i++) V.push_back(i);
	for (int i = 0; i < M; i++) {
		cin >> X[i].before >> X[i].after >> X[i].score;
	}
	do {
		int Y[9] = {};
		for (int i = 0; i < N; i++) {
			Y[V[i]] = i;
		}
		long long COUNT = 0;
		for (int i = 0; i < M; i++) {
			if (Y[X[i].before] < Y[X[i].after]) COUNT += X[i].score;
		}
		ANS = max(ANS, COUNT);
	} while (next_permutation(V.begin(), V.end()));
	cout << ANS << endl;
}
0