結果

問題 No.1380 Borderline
ユーザー eseharaesehara
提出日時 2021-06-02 09:40:37
言語 OCaml
(5.1.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,441 bytes
コンパイル時間 2,121 ms
コンパイル使用メモリ 19,692 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 18:01:47
合計ジャッジ時間 1,599 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 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 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 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 1 ms
5,376 KB
testcase_19 AC 1 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 1 ms
5,376 KB
testcase_24 AC 1 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 1 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 1 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 1 ms
5,376 KB
testcase_41 AC 1 ms
5,376 KB
testcase_42 AC 1 ms
5,376 KB
testcase_43 AC 1 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

(*
 N 人参加 -> 定員K
 定員を超えないようなボーダーを指定する

*)

let split_on_char sep s =
  let r = ref [] in
  let j = ref (String.length s) in
  for i = String.length s - 1 downto 0 do
    if String.unsafe_get s i = sep then begin
      r := String.sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  String.sub s 0 !j :: !r;;

(*

   ソートして降順にする 
    まず同じ点数の数を数え上げる
    違う点数になったら残り定員と比較する
     -> もし定員のほうが多ければ、そのまま定員を引く
     -> もし同じ点数の人数のほうが多ければ、その点数より +1かボーダーとなる

   今回は合格人数なので、元の定員の数から残った定員の数だけ引けば、合格人数が定まる
*)

let rec goukaku limit kazu ten lst =
  match lst with
  | [] -> if (kazu > limit) then limit else (limit - kazu)
  | h::tl ->
    if (h <> ten) then
      if (kazu > limit) then limit
      else goukaku (limit - kazu) 1 h tl
    else
      goukaku limit (kazu + 1) ten tl;;

let () =
  let raw = read_line () |> split_on_char ' ' |> List.map int_of_string in
  let k = List.nth raw 1 in
  let lst = read_line () |> split_on_char ' ' |> List.map int_of_string
            |> List.fast_sort (fun x y -> - (compare x y)) in
  let nokori = goukaku k 0 0 lst in
  print_int (k - nokori);
  print_newline ();;
0