結果
問題 | No.90 品物の並び替え |
ユーザー |
![]() |
提出日時 | 2014-12-07 21:47:53 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 146 ms / 5,000 ms |
コード長 | 986 bytes |
コンパイル時間 | 528 ms |
コンパイル使用メモリ | 75,476 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-11 17:33:54 |
合計ジャッジ時間 | 1,154 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
ソースコード
#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; }