結果

問題 No.2194 兄弟の掛け引き
ユーザー iwotiwot
提出日時 2023-02-17 16:39:00
言語 OCaml
(5.1.0)
結果
TLE  
実行時間 -
コード長 629 bytes
コンパイル時間 1,901 ms
コンパイル使用メモリ 19,640 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 15:17:05
合計ジャッジ時間 5,548 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
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
  [] -> ()
  | 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