結果

問題 No.2194 兄弟の掛け引き
ユーザー iwotiwot
提出日時 2023-02-17 16:36:04
言語 OCaml
(5.1.0)
結果
WA  
実行時間 -
コード長 643 bytes
コンパイル時間 2,277 ms
コンパイル使用メモリ 19,700 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 15:15:03
合計ジャッジ時間 6,087 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

let solve a b c =
  let max_n = (c + b) / a in
  let rec solve_core n =
    let ans = if n * a - b = c || n * a - b <= 0 && n * a = c then
      Some n
    else
      None
    in match ans with
    Some n when n = max_n -> n :: []
    | None when n = max_n -> []
    | None -> solve_core (n+1)
    | Some n -> n :: solve_core (n+1)
  in solve_core 1

let rec print_list = function
  [] -> print_endline ""
  | a :: rest -> print_endline (string_of_int a); print_list rest

let _ =
  let a, b, c = Scanf.scanf "%d %d %d" (fun a b c -> a, b, c) in
  let ans = solve a b c in
  if List.length ans > 0 then print_list ans
  else print_endline "-1"
0