結果
問題 | No.927 Second Permutation |
ユーザー |
|
提出日時 | 2020-06-16 23:29:03 |
言語 | OCaml (5.2.1) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 1,016 bytes |
コンパイル時間 | 295 ms |
コンパイル使用メモリ | 21,448 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-09 01:21:56 |
合計ジャッジ時間 | 1,405 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
Scanf.scanf "%s" (fun s ->let a = Array.make 10 0 inString.iter (fun c -> let n = int_of_char c - 48 in a.(n) <- a.(n) + 1) s;let rec loop i l =if i < 0 then l elseif a.(i) > 0 then loop (i - 1) (i :: l)else loop (i - 1) linlet show d1 d2 l =let digits = "0123456789" inlet rec loop acc = function| [] -> acc| hd :: tl -> loop (String.make a.(hd) digits.[hd] ^ acc) tlinlet acc = String.make (a.(d2) - 1) digits.[d2] ^String.make 1 digits.[d1] ^String.make 1 digits.[d2] ^String.make (a.(d1) - 1) digits.[d1]inloop acc linlet l = loop 9 [] inmatch l with| [] -> failwith "??"| [ _ ] -> print_endline "-1"| [ 0; d1 ] when a.(d1) = 1 -> print_endline "-1"| d1 :: d2 :: tl -> print_endline @@ show d1 d2 tl)