結果

問題 No.357 品物の並び替え (Middle)
ユーザー cielciel
提出日時 2016-04-02 01:05:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 953 bytes
コンパイル時間 579 ms
コンパイル使用メモリ 49,124 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 07:33:53
合計ジャッジ時間 1,368 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 5 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 9 ms
6,940 KB
testcase_13 AC 5 ms
6,944 KB
testcase_14 AC 5 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 |         scanf("%d%d",&N,&M);
      |         ~~~~~^~~~~~~~~~~~~~
main.cpp:39:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |                 scanf("%d%d%d",&a,&b,&c);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <set>
#include <stack>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;

typedef int Weight;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

const int M = 20;
Weight best[1<<M];
Weight shortestHamiltonPath(const Matrix &w, vector<int> &path) {
	int n=w.size();
	int N = 1 << n;
	REP(S,N) best[S] = 0;
	REP(S,N) REP(j,n) if (!(S&(1<<j))) {
		int score = 0;
		REP(i,n) if (S&(1<<i)) score+=w[i][j];
		REP(i,n) if (best[S|(1<<j)] <= best[S] + score) {
			best[S|(1<<j)] = best[S] + score;
		}
	}
	return best[N-1];
}

int main(){
	int N,M;
	scanf("%d%d",&N,&M);
	Matrix m(N);
	for(int i=0;i<N;i++)m[i].resize(N);
	for(;M--;){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		m[a][b]=c;
	}
	vector<int> path;
	printf("%d\n",shortestHamiltonPath(m,path));
}
0