結果

問題 No.90 品物の並び替え
ユーザー Ysmr_Ry
提出日時 2015-01-05 10:52:10
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 468 ms / 5,000 ms
コード長 664 bytes
コンパイル時間 485 ms
コンパイル使用メモリ 42,460 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-13 02:41:59
合計ジャッジ時間 1,500 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |         scanf( "%d%d", &N, &M );
      |         ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:17:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |                 scanf( "%d%d%d", item[0]+i, item[1]+i, score+i );
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<cstdio>
#include<algorithm>
#include<numeric>
#include<vector>
#define rep(i,a) for(int i=0;i<(a);++i)
#define all(a) (a).begin(), (a).end()

const int MAX_N = 9, MAX_M = 72;

int N, M;
int item[2][MAX_M], score[MAX_M];

int main()
{
	scanf( "%d%d", &N, &M );
	rep( i, M )
		scanf( "%d%d%d", item[0]+i, item[1]+i, score+i );

	std::vector<int> v( N );
	std::iota( all(v), 0 );

	int ans = 0;
	do
	{
		int cnt = 0;
		rep( i, M ) if( std::find( all(v), item[0][i] )-v.begin() < std::find( all(v), item[1][i] )-v.begin() )
			cnt += score[i];
	
		ans = std::max( ans, cnt );
	} while( std::next_permutation( all(v) ) );

	printf( "%d\n", ans );

	return 0;
}
0