結果

問題 No.349 干支の置き物
ユーザー ichibanshiboriichibanshibori
提出日時 2016-09-04 19:23:40
言語 OCaml
(5.1.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,274 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 20,992 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 08:33:44
合計ジャッジ時間 1,386 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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