結果

問題 No.90 品物の並び替え
ユーザー hotpepsihotpepsi
提出日時 2014-12-07 21:47:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 172 ms / 5,000 ms
コード長 986 bytes
コンパイル時間 664 ms
コンパイル使用メモリ 75,220 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-02 10:54:06
合計ジャッジ時間 1,538 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <sstream>
#include <vector>
#include <set>
#include <map>

using namespace std;

typedef pair<int, int> II;
typedef pair<int, II> III;
typedef vector<III> IIIVec;

int main(int argc, char *argv[])
{
	int N, M;
	string s;
	{
		getline(cin, s);
		stringstream ss(s);
		ss >> N >> M;
	}
	IIIVec v;
	for (int i = 0; i < M; ++i) {
		getline(cin, s);
		stringstream ss(s);
		int a, b, c;
		ss >> a >> b >> c;
		v.push_back(III(a, II(b, c)));
	}

	int ans = 0;
	int seq[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
	do {
		int sum = 0;
		for (int i = 0; i < (int)v.size(); ++i) {
			III &x = v[i];
			bool f = true;
			int j;
			for (j = 0; j < N; ++j) {
				if (seq[j] == x.first) {
					sum += x.second.second;
					break;
				}
				if (seq[j] == x.second.first) {
					break;
				}
			}
		}
		ans = max(ans, sum);
	} while (next_permutation(seq, seq + N));

	cout << ans << endl;

	return 0;
}
0