Submission #8976622
Source Code Expand
open System.Collections.Generic
let n = stdin.ReadLine() |> int
let array6 =
[|
let mutable count = 1
while count<= 100000 do
yield count
count <- count * 6
|]
let array9 =
[|
let mutable count = 1
while count<= 100000 do
yield count
count <- count * 9
|]
/// メモ化再帰に用いる辞書
let cache = Dictionary<_,_>()
let memoize f =
fun x ->
if cache.ContainsKey(x) then cache.[x]
else
cache.[x] <- f x
cache.[x]
/// メモ化再帰
let rec memCount n=
let count n=
if n <> 0 then
let cand1 =
n - (array6 |> Array.findBack (fun x -> x <= n))
let cand2 =
n - (array9 |> Array.findBack (fun x -> x <= n))
min
(memCount cand1)
(memCount cand2)
+ 1
else 0
let memCount = memoize count
memCount n
memCount n |> stdout.WriteLine
Submission Info
| Submission Time | |
|---|---|
| Task | C - Strange Bank |
| User | pota |
| Language | F# (Mono 4.0) |
| Score | 300 |
| Code Size | 1056 Byte |
| Status | AC |
| Exec Time | 27 ms |
| Memory | 13268 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, sample_01.txt, sample_02.txt, sample_03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01.txt | AC | 27 ms | 11232 KiB |
| 02.txt | AC | 27 ms | 11232 KiB |
| 03.txt | AC | 26 ms | 9184 KiB |
| 04.txt | AC | 27 ms | 11356 KiB |
| 05.txt | AC | 27 ms | 11348 KiB |
| 06.txt | AC | 26 ms | 11232 KiB |
| 07.txt | AC | 27 ms | 13268 KiB |
| 08.txt | AC | 27 ms | 11232 KiB |
| 09.txt | AC | 27 ms | 13268 KiB |
| 10.txt | AC | 27 ms | 11356 KiB |
| 11.txt | AC | 26 ms | 11232 KiB |
| 12.txt | AC | 26 ms | 9184 KiB |
| 13.txt | AC | 27 ms | 11232 KiB |
| 14.txt | AC | 27 ms | 11356 KiB |
| 15.txt | AC | 27 ms | 11356 KiB |
| 16.txt | AC | 26 ms | 9300 KiB |
| sample_01.txt | AC | 27 ms | 11360 KiB |
| sample_02.txt | AC | 27 ms | 11232 KiB |
| sample_03.txt | AC | 26 ms | 11232 KiB |