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 | let compare x range = (if (fst range)+1 < x then 1 else 0), (if (snd range)+1 < x then 1 else 0) let insert range xs = let rec impl range xs ret = if xs = [] then (range::ret) else let head = List.hd xs in let tail = List.tl xs in match compare (fst range) head, compare (snd range) head with | (0, 0), (0, 0) -> range::xs | (0, 0), (1, 1) -> impl range tail ret | (1, 1), (1, 1) -> impl range tail (head::ret) | (0, 0), (1, 0) -> impl ((fst range), (snd head)) tail ret | (1, 0), (1, 1) -> impl ((fst head), (snd range)) tail ret | _ -> xs in impl range xs [] let main = let ret = [] in let num = Scanf.scanf "%d\n" (fun n -> n) in let input () = Scanf.scanf "%d %d\n" (fun h t -> (h, t)) in List.iter (fun r -> Printf.printf "%d %d\n" (fst r) (snd r)) ( List.sort Pervasives.compare ( let rec loop n ret = if n = 0 then ret else loop (n-1) (insert (input ()) ret) in loop (num-1) (input () :: ret))) |
-
upload with new input
-
結果: Success time: 0s 記憶體: 2780 kB 回傳值: 0
5 0 10 20 30 40 50 60 70 0 100
0 100
-
結果: Success time: 0s 記憶體: 2780 kB 回傳值: 0
2 0 10 11 20
0 20
-
結果: Success time: 0s 記憶體: 2780 kB 回傳值: 0
2 0 10 5 7
0 10
-
結果: Success time: 0s 記憶體: 2780 kB 回傳值: 0
3 10 19 0 15 20 29
0 29
-
結果: Success time: 0s 記憶體: 2780 kB 回傳值: 2
2 0 10 5 7
Fatal error: exception End_of_file
-
結果: Success time: 0s 記憶體: 2780 kB 回傳值: 0
3 10 19 0 15 20 29
0 29
-
結果: Success time: 0s 記憶體: 2780 kB 回傳值: 0
2 0 9 20 29
0 9 20 29
-
結果: Success time: 0s 記憶體: 2780 kB 回傳值: 0
2 0 10 5 19
0 19



