結果

問題 No.90 品物の並び替え
ユーザー kapokapo
提出日時 2016-04-29 15:37:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 247 ms / 5,000 ms
コード長 711 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 22,656 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 05:24:10
合計ジャッジ時間 970 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 18 ms
6,940 KB
testcase_02 AC 0 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 21 ms
6,944 KB
testcase_06 AC 14 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 247 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |         scanf("%d %d", &n, &m);
      |         ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:45:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |                 scanf("%d %d %d", &a[i], &b[i], &c[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp: In function ‘int score()’:
main.cpp:14:17: warning: ‘r’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   14 |                 if( l < r) x += c[i];
      |                 ^~
main.cpp:14:17: warning: ‘l’ may be used uninitialized in this function [-Wmaybe-uninitialized]

ソースコード

diff #

#include <stdio.h>

int a[72], b[72], c[72], n, m, used[9]={}, d[9], sum=0;

int score()
{
	int x = 0, i, j;
	for( i = 0; i < m; i++) {
		int l, r;
		for( j = 0; j < n; j++) {
			if( a[i] == d[j]) l = j;
			if( b[i] == d[j]) r = j;
		}
		if( l < r) x += c[i];
	}
	return x;
}

void saiki2(int num)
{
	int i;

	if( num == n) {
		int x2;
		x2 = score();
		if( x2 > sum ) sum = x2;
	} else {
		for( i = 0; i < n; i++) {
			if(used[i] == 0) {
				used[i] = 1;
				d[num] = i;
				saiki2(num + 1);
				used[i] = 0;
				d[num] = 10;
			}
		}
	}
}

int main(void)
{
	int i;
	scanf("%d %d", &n, &m);
	for( i = 0; i < m; i++) {
		scanf("%d %d %d", &a[i], &b[i], &c[i]);
	}
	saiki2(0);
	printf("%d\n", sum);

	return 0;
}
0