結果

問題 No.216 FAC
ユーザー ichibanshiboriichibanshibori
提出日時 2017-05-07 21:48:24
言語 OCaml
(5.1.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,584 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 19,696 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 08:36:42
合計ジャッジ時間 1,040 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

let list_group_by cmp lst =
  let rec list_group_by' lst result =
    match lst with
    | [] -> result
    | x::xs ->
      let value = cmp x in
      let lst1, lst2 = List.partition (fun v -> value = cmp v) lst in
      list_group_by' lst2 ((value, lst1)::result)
  in
  list_group_by' lst []

let list_sum_by f lst =
  List.fold_left (fun e1 e2 -> e1 + (f e2)) 0 lst

let list_max_by f lst =
  let rec list_max_by' lst result =
    match lst with
    | [] -> result
    | x::xs ->
      let v = f x in
      let result = max result v in
      list_max_by' xs result
  in
  if (List.length lst) <= 0 then failwith "list_max_by"
  else list_max_by' (List.tl lst) (f (List.hd lst))



let solve a_lst b_lst =
  let ab_lst = List.combine a_lst b_lst in
  let other_score =
    List.filter (fun (a, b) -> b <> 0) ab_lst
    |> fun lst ->
      match lst with
      | [] -> 0
      | _ ->
        list_group_by (fun (_, b) -> b) lst
        |> List.map (fun (b, ab_lst) -> list_sum_by (fun (a, b) -> a) ab_lst)
        |> list_max_by (fun i -> i)
  and k_score =
    List.filter (fun (a, b) -> b = 0) ab_lst
    |> fun lst ->
      match lst with
      | [] -> 0
      | _ -> list_sum_by (fun (a, b) -> a) lst
  in
  if k_score >= other_score then
    "YES"
  else
    "NO"

let () =
  let _ = read_line ()
  and a_lst = read_line ()
              |> Str.split (Str.regexp_string " ")
              |> List.map int_of_string
  and b_lst = read_line ()
              |> Str.split (Str.regexp_string " ")
              |> List.map int_of_string
  in
  solve a_lst b_lst
  |> print_endline
0