結果
問題 |
No.825 賢いお買い物
|
ユーザー |
|
提出日時 | 2020-06-20 19:46:29 |
言語 | OCaml (5.2.1) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 696 bytes |
コンパイル時間 | 271 ms |
コンパイル使用メモリ | 21,576 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-09 01:31:49 |
合計ジャッジ時間 | 1,226 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
Scanf.scanf "%d %d %d" (fun a b c -> let calc rest cost = let rec loop i = if i > cost then max_int else let r2 = rest + (cost - i) / 10 + (cost - i) mod 10 in if r2 = c then i else loop (i + 1) in loop 1 in let rec loop_i i acc = let rec loop_j j acc = if j > a then acc else let rest = calc (b - i + a - j) (i * 10 + j) in loop_j (j + 1) (min acc rest) in if i > b then acc else loop_i (i + 1) (loop_j 0 acc) in let ans = loop_i 0 max_int in if ans = max_int then print_endline "Impossible" else Printf.printf "%d\n" ans )