結果

問題 No.845 最長の切符
ユーザー pekempeypekempey
提出日時 2019-06-28 22:02:34
言語 OCaml
(5.1.0)
結果
AC  
実行時間 242 ms / 3,000 ms
コード長 765 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 19,972 KB
実行使用メモリ 15,308 KB
最終ジャッジ日時 2023-07-30 07:20:25
合計ジャッジ時間 4,819 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 50 ms
8,100 KB
testcase_16 AC 239 ms
14,592 KB
testcase_17 AC 50 ms
7,568 KB
testcase_18 AC 109 ms
9,972 KB
testcase_19 AC 24 ms
5,896 KB
testcase_20 AC 239 ms
15,256 KB
testcase_21 AC 240 ms
15,144 KB
testcase_22 AC 50 ms
7,480 KB
testcase_23 AC 12 ms
5,072 KB
testcase_24 AC 236 ms
14,612 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 209 ms
15,284 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 242 ms
15,308 KB
testcase_29 AC 2 ms
4,376 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