結果

問題 No.360 増加門松列
ユーザー kuuso1kuuso1
提出日時 2016-09-13 00:40:56
言語 F#
(F# 4.0)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 1,209 bytes
コンパイル時間 4,820 ms
コンパイル使用メモリ 172,724 KB
実行使用メモリ 29,672 KB
最終ジャッジ日時 2023-08-25 18:40:54
合計ジャッジ時間 8,165 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
27,412 KB
testcase_01 AC 122 ms
27,516 KB
testcase_02 AC 114 ms
27,480 KB
testcase_03 AC 104 ms
25,452 KB
testcase_04 AC 121 ms
27,488 KB
testcase_05 AC 119 ms
29,520 KB
testcase_06 AC 118 ms
27,548 KB
testcase_07 AC 117 ms
27,612 KB
testcase_08 AC 118 ms
29,576 KB
testcase_09 AC 120 ms
29,452 KB
testcase_10 AC 114 ms
29,532 KB
testcase_11 AC 103 ms
27,568 KB
testcase_12 AC 121 ms
27,604 KB
testcase_13 AC 118 ms
29,604 KB
testcase_14 AC 100 ms
21,428 KB
testcase_15 AC 113 ms
29,564 KB
testcase_16 AC 103 ms
23,468 KB
testcase_17 AC 103 ms
25,408 KB
testcase_18 AC 122 ms
29,484 KB
testcase_19 AC 120 ms
29,492 KB
testcase_20 AC 117 ms
27,512 KB
testcase_21 AC 121 ms
29,672 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

ソースコード

diff #

open System

let rec insertions x = function
    | []             -> [[x]]
    | (y :: ys) as l -> (x::l)::(List.map (fun x -> y::x) (insertions x ys))

let rec permutations = function
    | []      -> seq [ [] ]
    | x :: xs -> Seq.concat (Seq.map (insertions x) (permutations xs))

let ri () = stdin.ReadLine() |> int
let ria () = stdin.ReadLine().Split() |> Array.map int

let zip3 a b c =
    Seq.zip a b 
    |> Seq.zip c
    |> Seq.map (fun (z,(x,y)) -> (x,y,z) )

let isKadmatsu (x,y,z) = ( x <> y ) && ( y <> z) && (x <> z) && ( ((x < y) && (y > z)) || ((x > y) && (y < z)))
let isAscendingKadomatsu ((x:int),(y:int),(z:int)) = ( isKadmatsu (x,y,z) ) && (x < z)

let isAscendingKadomatsuSeq (a:int list) = 
    let a3 = zip3 a (Seq.skip 1 a) (Seq.skip 2 a)
    a3 |> Seq.map isAscendingKadomatsu |> Seq.reduce (fun x s -> x && s)
    
type Sol() =
    member this.Solve() = 
        let D = ria() |> Array.toList
        let permu = permutations D
        
        let ret = Seq.tryFind  (fun ar -> isAscendingKadomatsuSeq ar ) permu
        if (Option.isSome ret) then "YES" else "NO"
        |> printfn "%s"
                                   
        
        
let mySol = new Sol()
mySol.Solve()
0