結果

問題 No.845 最長の切符
ユーザー bal4ubal4u
提出日時 2019-06-29 06:57:36
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 1,203 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 30,188 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-14 22:59:31
合計ジャッジ時間 5,072 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,760 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 0 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 0 ms
4,376 KB
testcase_07 AC 0 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 59 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:7:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    7 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:13:24: 備考: in expansion of macro ‘gc’
   13 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

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

#include <stdio.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;
}

typedef struct { int a, c, p; } Q;
Q q[10000]; int top;
int N, M, MASK;
int map[17][17];
int to[17][17], ds[17][17], hi[17];

int dfs(int s) {
	int i, a, b, c, p, ans = 0;
	top = 1, q[0].a = s, q[0].c = 0, q[0].p = 1<<s;
	while (top) {
		a = q[--top].a, c = q[top].c, p = q[top].p;
		if (c > ans) ans = c;
		for (i = 0; i < hi[a]; i++) {
			b = to[a][i];
			if (((p | ~(1<<b)) & MASK) == MASK) continue;
			q[top].a = b, q[top].c = c + ds[a][i], q[top].p = p | (1<<b);
			top++;
		}
	}
	return ans;
}
			
int main()
{
	int k, a, b, c, ans;

	N = in(), M = in(), MASK = (1<<N)-1;
	while (M--) {
		a = in()-1, b = in()-1, c = in();
		if (map[a][b] < c) map[a][b] = map[b][a] = c;
	}
	for (a = 0; a < N; a++) for (b = 0; b < N; b++) if (a != b) {
		if (map[a][b]) k = hi[a]++, to[a][k] = b, ds[a][k] = map[a][b];
	}
	
	ans = 0; for (a = 0; a < N; a++) {
		if ((k = dfs(a)) > ans) ans = k;
	}
	printf("%d\n", ans);
	return 0;
}
0