結果

問題 No.927 Second Permutation
ユーザー xsdxsd
提出日時 2020-06-16 23:29:03
言語 OCaml
(5.1.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,016 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 21,572 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 08:58:59
合計ジャッジ時間 1,294 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 5 ms
5,376 KB
testcase_17 AC 5 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 5 ms
5,376 KB
testcase_23 AC 5 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 4 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

Scanf.scanf "%s" (fun s ->
    let a = Array.make 10 0 in
    String.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 else
            if a.(i) > 0 then loop (i - 1) (i :: l)
                         else loop (i - 1) l
    in
    let show d1 d2 l =
        let digits = "0123456789" in
        let rec loop acc = function
            | [] -> acc
            | hd :: tl -> loop (String.make a.(hd) digits.[hd] ^ acc) tl
        in
        let 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]
        in
        loop acc l
    in
    let l = loop 9 [] in
    match l with
    | []                        -> failwith "??"
    | [ _ ]                     -> print_endline "-1"
    | [ 0; d1 ] when a.(d1) = 1 -> print_endline "-1"
    | d1 :: d2 :: tl -> print_endline @@ show d1 d2 tl
)
0