結果

問題 No.1380 Borderline
ユーザー eseharaesehara
提出日時 2021-06-02 09:35:55
言語 OCaml
(5.1.0)
結果
WA  
実行時間 -
コード長 1,437 bytes
コンパイル時間 1,530 ms
コンパイル使用メモリ 19,816 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 17:58:55
合計ジャッジ時間 2,914 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 1 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
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 1 ms
5,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
5,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 1 ms
5,376 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 1 ms
5,376 KB
testcase_38 WA -
testcase_39 AC 1 ms
5,376 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 2 ms
5,376 KB
testcase_43 WA -
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