-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkupc2013-B.fsx
More file actions
31 lines (25 loc) · 1.13 KB
/
kupc2013-B.fsx
File metadata and controls
31 lines (25 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(*
http://kupc2013.contest.atcoder.jp/tasks/kupc2013_b
*)
let isValid (cages : int[]) (startIndex, endIndex, total) =
cages.[startIndex - 1 .. endIndex - 1] |> Array.sum |> (=) total
let getAllPatterns cageCount maxLionCount =
let rec getAllPatterns result = function
| 0 -> result
| cageCount ->
let r = result |> Seq.collect (fun xs -> [for i in maxLionCount .. -1 .. 0 -> Array.append xs [|i|]])
cageCount - 1 |> getAllPatterns r
getAllPatterns [[||]] cageCount
let tryFind cageCount maxLionCount counts =
getAllPatterns cageCount maxLionCount |> Seq.tryFind (fun cages -> counts |> List.forall (isValid cages))
open System
let main() =
let [|cageCount; maxLionCount; counterCount|] = Console.ReadLine().Split([|' '|]) |> Array.map int
let counts =
[for _ in 1 .. counterCount ->
let input = Console.ReadLine().Split([|' '|])
int input.[0], int input.[1], int input.[2]]
match tryFind cageCount maxLionCount counts with
| Some result -> result |> Seq.map string |> String.concat " " |> printfn "%s"
| None -> printfn "%d" -1
main()