結果

問題 No.845 最長の切符
ユーザー pekempeypekempey
提出日時 2019-06-28 22:02:34
言語 OCaml
(5.1.0)
結果
AC  
実行時間 255 ms / 3,000 ms
コード長 765 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 21,484 KB
実行使用メモリ 13,952 KB
最終ジャッジ日時 2024-04-17 08:48:27
合計ジャッジ時間 3,029 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 4 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 6 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 4 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 4 ms
6,940 KB
testcase_15 AC 53 ms
7,040 KB
testcase_16 AC 255 ms
13,952 KB
testcase_17 AC 51 ms
6,940 KB
testcase_18 AC 109 ms
8,064 KB
testcase_19 AC 25 ms
6,944 KB
testcase_20 AC 246 ms
13,824 KB
testcase_21 AC 251 ms
13,952 KB
testcase_22 AC 53 ms
6,944 KB
testcase_23 AC 12 ms
6,944 KB
testcase_24 AC 252 ms
13,952 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 223 ms
13,952 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 251 ms
13,952 KB
testcase_29 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

let n, m = Scanf.scanf "%d %d" (fun x y -> x, y);;

let inf = max_int / 4;;
let g = Array.make_matrix n n (-inf);;

for i = 1 to m do
  let a, b, c = Scanf.scanf " %d %d %d" (fun x y z -> x-1, y-1, z) in
  g.(a).(b) <- max g.(a).(b) c;
  g.(b).(a) <- max g.(b).(a) c;
done;;

let dp = Array.make_matrix (1 lsl n) (n) (-inf);;
for i = 0 to n - 1 do
  dp.(1 lsl i).(i) <- 0;
done;;
  
for i = 0 to (1 lsl n) - 1 do
  for j = 0 to n - 1 do
    for k = 0 to n - 1 do
      if (i lsr k) mod 2 == 0 then
        dp.(i lor (1 lsl k)).(k) <- max dp.(i lor (1 lsl k)).(k) (dp.(i).(j) + g.(j).(k));
    done
  done
done;;

let ans = ref (-inf);;
for i = 0 to (1 lsl n) - 1 do
  for j = 0 to n - 1 do
    ans := max !ans dp.(i).(j);
  done
done;;

Printf.printf "%d\n" !ans;;
0