結果

問題 No.349 干支の置き物
ユーザー ichibanshibori
提出日時 2016-09-04 19:23:40
言語 OCaml
(5.2.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,274 bytes
コンパイル時間 354 ms
コンパイル使用メモリ 20,988 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-08 23:47:56
合計ジャッジ時間 1,476 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

let group_by cmp lst =
    let rec hdsplit hdval lst (lst1, lst2)  =
      if lst = [] then (lst1, lst2)
      else match cmp (List.hd lst) with
      | v when v = hdval -> hdsplit hdval (List.tl lst) ((List.hd lst):: lst1, lst2)
      | _ -> hdsplit hdval (List.tl lst) (lst1, (List.hd lst):: lst2)
    in
    let rec make_result lst result =
      match lst with
      | [] -> result
      | x::xs ->
          let lst1, lst2 = hdsplit (cmp x) lst ([], []) in
          make_result lst2 ((cmp x, lst1)::result)
    in
    make_result lst []

let judge_eto (lst: string list) =
    let glst = group_by (fun id -> id) lst in
    let rec get_max_length lst result =
        match lst with
        | [] -> result
        | x::xs ->
            let maxVal = max (List.length x) result in
            get_max_length xs maxVal
    in
    let elst = glst |> List.map (fun (_, lst) -> lst) in
    let mlen = get_max_length elst 0
    and ilen = List.length lst in
    int_of_float (ceil ((float_of_int ilen) /. 2.)) >= mlen
    
let () =
    let n = read_int ()
    and  elst = ref [] in
    for i = 1 to n do
        let line = read_line () in
        elst := line :: !elst
    done;
    (!elst) |> judge_eto |> (function | true -> "YES" | false -> "NO") |> (Printf.printf "%s\n")
0