結果

問題 No.90 品物の並び替え
ユーザー MayimgMayimg
提出日時 2018-11-28 13:11:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 632 ms / 5,000 ms
コード長 795 bytes
コンパイル時間 1,618 ms
コンパイル使用メモリ 167,768 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-09 03:19:17
合計ジャッジ時間 3,216 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m; cin >> n >> m;
	vector<int> items(n);
	vector<int> front(m), back(m), score(m);
	for(int i = 0; i < m; i++) {
		cin >> front[i] >> back[i] >> score[i];
	}
	for(int i = 0; i < n; i++) {
		items[i] = i;
	}
	int ans = 0;
	do{
		int tmp = 0;
		for(int i = 0; i < m; i++) {
			int f = -1, b = -1;
			for(int j = 0; j < n; j++) {
				if(items[j] == front[i]) f = j;
				if(items[j] == back[i])  b = j;
				if(b > f && f > -1 && b > -1) {
					tmp += score[i];
					break;
				}
			}
		}
		ans = max(tmp, ans);
	}while(next_permutation(items.begin(), items.end()));
	cout << ans << endl;
	return 0;                                              
}
	
0