結果

問題 No.334 門松ゲーム
ユーザー vain0vain0
提出日時 2016-01-16 15:29:00
言語 F#
(.NET 7)
結果
AC  
実行時間 378 ms / 2,000 ms
コード長 1,197 bytes
コンパイル時間 12,291 ms
コンパイル使用メモリ 191,280 KB
実行使用メモリ 56,428 KB
最終ジャッジ日時 2023-10-20 00:06:55
合計ジャッジ時間 15,205 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 368 ms
37,268 KB
testcase_01 AC 82 ms
32,368 KB
testcase_02 AC 122 ms
46,968 KB
testcase_03 AC 364 ms
37,112 KB
testcase_04 AC 366 ms
37,192 KB
testcase_05 AC 365 ms
37,300 KB
testcase_06 AC 377 ms
41,012 KB
testcase_07 AC 108 ms
40,956 KB
testcase_08 AC 372 ms
39,368 KB
testcase_09 AC 100 ms
37,100 KB
testcase_10 AC 148 ms
56,428 KB
testcase_11 AC 378 ms
41,244 KB
testcase_12 AC 368 ms
38,260 KB
testcase_13 AC 369 ms
37,944 KB
testcase_14 AC 96 ms
36,332 KB
testcase_15 AC 372 ms
39,432 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (385 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

open System

let is_kadomatsu (x, y, z) =
    x <> y && y <> z
    && (x < y || y < z)
    && (x > y || y > z)

let erase_all_at is xs =
    [| for i in 0..(Array.length xs - 1) do
        if is |> Set.contains i |> not then yield xs.[i]
    |]

// 部分門松列の列挙
let enum_subkadomatsus (xs: _ []) =
    let n = xs.Length
    [ for i in 0..(n - 1) do
        for j in (i + 1)..(n - 1) do
          for k in (j + 1)..(n - 1) do
              if (xs.[i], xs.[j], xs.[k]) |> is_kadomatsu then
                let ys = xs |> erase_all_at (Set.ofList [i; j; k])
                yield ((i, j, k), ys)
    ]

// ある部分門松列を消して絶対に勝てるなら、それを返す
let rec fr_turn ks =
    enum_subkadomatsus ks
    |> List.tryFind (fun (i3, ks') ->
        en_turn ks'
        )

and en_turn ks =
    enum_subkadomatsus ks
    |> List.forall (fun ((x, y, z), ks') ->
        fr_turn ks' |> Option.isSome
        )

[<EntryPoint>]
let main _ =
  let _ = Console.ReadLine() |> int
  let ks = Console.ReadLine().Split(' ') |> Array.map int

  match fr_turn ks with
  | Some ((i, j, k), _) ->
      printfn "%d %d %d" i j k
  | None ->
      printfn "-1"

  //exit code
  0
0