結果
| 問題 | 
                            No.216 FAC
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2017-05-07 21:48:24 | 
| 言語 | OCaml  (5.2.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 1,000 ms | 
| コード長 | 1,584 bytes | 
| コンパイル時間 | 301 ms | 
| コンパイル使用メモリ | 19,712 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-09 00:00:43 | 
| 合計ジャッジ時間 | 1,210 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 24 | 
ソースコード
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