結果

問題 No.90 品物の並び替え
ユーザー 0w10w1
提出日時 2016-11-21 00:09:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 5,000 ms
コード長 692 bytes
コンパイル時間 1,563 ms
コンパイル使用メモリ 173,024 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-18 05:59:58
合計ジャッジ時間 2,288 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

signed main(){
  int N, M; cin >> N >> M;
  vector< tuple< int, int, int > > abv( M );
  for( int i = 0; i < M; ++i ){
    int a, b, v; cin >> a >> b >> v;
    abv[ i ] = tie( a, b, v );
  }
  int ans = 0;
  vector< int > item( N );
  for( int i = 0; i < N; ++i )
    item[ i ] = i;
  do{
    int sum = 0;
    vector< int > pos( N );
    for( int i = 0; i < N; ++i )
      pos[ item[ i ] ] = i;
    for( int i = 0; i < M; ++i ){
      int a, b, v; tie( a, b, v ) = abv[ i ];
      sum += ( pos[ a ] < pos[ b ] ) * v;
    }
    ans = max( ans, sum );
  } while( next_permutation( item.begin(), item.end() ) );
  cout << ans << endl;
  return 0;
}
0