結果
問題 | No.845 最長の切符 |
ユーザー | bal4u |
提出日時 | 2019-06-29 20:41:52 |
言語 | C (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 74 ms / 3,000 ms |
コード長 | 996 bytes |
コンパイル時間 | 583 ms |
コンパイル使用メモリ | 29,824 KB |
実行使用メモリ | 5,952 KB |
最終ジャッジ日時 | 2023-09-14 23:22:47 |
合計ジャッジ時間 | 1,843 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,824 KB |
testcase_01 | AC | 3 ms
5,876 KB |
testcase_02 | AC | 2 ms
5,860 KB |
testcase_03 | AC | 2 ms
5,944 KB |
testcase_04 | AC | 2 ms
5,876 KB |
testcase_05 | AC | 2 ms
5,840 KB |
testcase_06 | AC | 2 ms
5,948 KB |
testcase_07 | AC | 2 ms
5,812 KB |
testcase_08 | AC | 3 ms
5,876 KB |
testcase_09 | AC | 2 ms
5,872 KB |
testcase_10 | AC | 4 ms
5,872 KB |
testcase_11 | AC | 3 ms
5,952 KB |
testcase_12 | AC | 3 ms
5,880 KB |
testcase_13 | AC | 3 ms
5,896 KB |
testcase_14 | AC | 3 ms
5,836 KB |
testcase_15 | AC | 17 ms
5,836 KB |
testcase_16 | AC | 63 ms
5,880 KB |
testcase_17 | AC | 16 ms
5,948 KB |
testcase_18 | AC | 32 ms
5,876 KB |
testcase_19 | AC | 9 ms
5,896 KB |
testcase_20 | AC | 74 ms
5,856 KB |
testcase_21 | AC | 70 ms
5,944 KB |
testcase_22 | AC | 16 ms
5,932 KB |
testcase_23 | AC | 5 ms
5,936 KB |
testcase_24 | AC | 65 ms
5,840 KB |
testcase_25 | AC | 3 ms
5,816 KB |
testcase_26 | AC | 14 ms
5,824 KB |
testcase_27 | AC | 2 ms
5,904 KB |
testcase_28 | AC | 19 ms
5,876 KB |
testcase_29 | AC | 2 ms
5,820 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(); | ^~
ソースコード
// 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; } } } ans = 0; for (i = 0; i < lim; i++) for (a = 0; a < N; a++) if (dp[i][a] > ans) ans = dp[i][a]; printf("%d\n", ans); return 0; }