結果

問題 No.845 最長の切符
ユーザー bal4ubal4u
提出日時 2019-06-29 20:37:12
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 88 ms / 3,000 ms
コード長 937 bytes
コンパイル時間 1,312 ms
コンパイル使用メモリ 29,696 KB
実行使用メモリ 5,952 KB
最終ジャッジ日時 2023-09-14 23:22:45
合計ジャッジ時間 2,008 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,808 KB
testcase_01 AC 3 ms
5,816 KB
testcase_02 AC 3 ms
5,884 KB
testcase_03 AC 3 ms
5,864 KB
testcase_04 AC 3 ms
5,840 KB
testcase_05 AC 2 ms
5,812 KB
testcase_06 AC 3 ms
5,856 KB
testcase_07 AC 3 ms
5,944 KB
testcase_08 AC 3 ms
5,944 KB
testcase_09 AC 3 ms
5,860 KB
testcase_10 AC 4 ms
5,924 KB
testcase_11 AC 3 ms
5,844 KB
testcase_12 AC 3 ms
5,948 KB
testcase_13 AC 3 ms
5,816 KB
testcase_14 AC 3 ms
5,856 KB
testcase_15 AC 19 ms
5,896 KB
testcase_16 AC 80 ms
5,940 KB
testcase_17 AC 18 ms
5,876 KB
testcase_18 AC 39 ms
5,820 KB
testcase_19 AC 10 ms
5,944 KB
testcase_20 AC 88 ms
5,952 KB
testcase_21 AC 87 ms
5,952 KB
testcase_22 AC 17 ms
5,868 KB
testcase_23 AC 6 ms
5,812 KB
testcase_24 AC 82 ms
5,816 KB
testcase_25 AC 2 ms
5,940 KB
testcase_26 AC 19 ms
5,932 KB
testcase_27 AC 3 ms
5,872 KB
testcase_28 AC 34 ms
5,932 KB
testcase_29 AC 2 ms
5,812 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:8:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:14:24: 備考: in expansion of macro ‘gc’
   14 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: No.845 最長の切符
// 2019.6.29 bal4u

#include <stdio.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

int N, M;
int map[16][16];
int dp[65536][16];

int main()
{
	int i, a, b, c, lim, ans;

	N = in(), M = in();
	while (M--) {
		a = in()-1, b = in()-1, c = in();
		if (map[a][b] < c) map[a][b] = map[b][a] = c;
	}

	lim = 1 << N, ans = 0;
	memset(dp, -1, sizeof(dp));
	
	for (a = 0; a < N; a++) dp[1<<a][a] = 0;
	for (i = 0; i < lim; i++) {
		for (a = 0; a < N; a++) for (b = 0; b < N; b++) if (map[a][b] > 0) {
			if (((i >> a) & 1) && !((i >> b) & 1) && dp[i][a] >= 0) {
				c = dp[i][a] + map[a][b];
				if (c > dp[i|(1<<b)][b]) {
					dp[i|(1<<b)][b] = c;
					if (c > ans) ans = c;
				}
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}
0