結果

問題 No.90 品物の並び替え
ユーザー kyo1kyo1
提出日時 2020-10-21 06:12:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 241 ms / 5,000 ms
コード長 642 bytes
コンパイル時間 2,493 ms
コンパイル使用メモリ 201,040 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-28 14:05:28
合計ジャッジ時間 3,492 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  vector<int> A(M), B(M), C(M);
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i] >> C[i];
  }
  vector<int> P(N);
  iota(P.begin(), P.end(), 0);
  int res = 0;
  do {
    int r = 0;
    for (int i = 0; i < M; i++) {
      int a = 0, b = 0;
      for (int j = 0; j < N; j++) {
        if (A[i] == P[j]) a = j;
        if (B[i] == P[j]) b = j;
      }
      if (a < b) r += C[i];
    }
    res = max(res, r);
  } while (next_permutation(P.begin(), P.end()));
  cout << res << '\n';
  return 0;
}
0