結果

問題 No.90 品物の並び替え
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-08-07 22:16:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 443 ms / 5,000 ms
コード長 694 bytes
コンパイル時間 518 ms
コンパイル使用メモリ 66,304 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 00:29:04
合計ジャッジ時間 1,541 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

int main(void){
	int n, m; cin >> n >> m;
	vector<pair<int, int> > sinamono(m);
	vector<int> score(m);
	rep(i, m) cin >> sinamono[i].first >> sinamono[i].second >> score[i];

	vector<int> v;
	rep(i, n) v.push_back(i);

	int ans = 0;
	do{
		int tmp = 0;
		rep(i, m){
			auto itr1 = find(v.begin(), v.end(), sinamono[i].first);
			auto itr2 = find(v.begin(), v.end(), sinamono[i].second);
			if(itr2 - v.begin() > itr1 - v.begin()) tmp += score[i];
		}
		ans = max(ans, tmp);
	}while(next_permutation(v.begin(), v.end()));
	printf("%d\n", ans);
	return 0;
}
0