結果

問題 No.357 品物の並び替え (Middle)
ユーザー FF256grhyFF256grhy
提出日時 2016-04-02 03:10:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 697 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 23,808 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 07:38:45
合計ジャッジ時間 869 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>

int score[14][14], dp[1 << 14], queue[1 << 14], get = 0, set = 0;

int main() {
	int n, m, i, j;
	scanf("%d%d", &n, &m);
	for(i = 0; i < m; i++) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		score[a][b] = c;
	}
	
	dp[0] = 1;
	//queue[0] = 0;
	set++;
	
	while(get != set) {
		for(i = 0; i < n; i++) {
			if( ( queue[get] & (1 << i) ) == 0 ) {
				int next = queue[get] + (1 << i);
				int s = dp[ queue[get] ];
				for(j = 0; j < n; j++) {
					if( queue[get] & (1 << j) ) { s += score[j][i]; }
				}
				if(dp[next] == 0) { queue[set] = next; set++; }
				dp[next] = dp[next] < s ? s : dp[next];
			}
		}
		get++;
	}
	
	printf("%d\n", dp[(1 << n) - 1] - 1);
	
	return 0;
}
0