結果

問題 No.1045 直方体大学
ユーザー ikdikd
提出日時 2020-05-03 02:08:36
言語 F#
(F# 4.0)
結果
TLE  
実行時間 -
コード長 1,499 bytes
コンパイル時間 5,686 ms
コンパイル使用メモリ 172,024 KB
実行使用メモリ 29,272 KB
最終ジャッジ日時 2023-08-30 17:56:25
合計ジャッジ時間 9,153 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
23,324 KB
testcase_01 AC 91 ms
25,336 KB
testcase_02 AC 90 ms
21,268 KB
testcase_03 AC 91 ms
23,396 KB
testcase_04 AC 91 ms
23,204 KB
testcase_05 AC 123 ms
25,272 KB
testcase_06 AC 126 ms
29,272 KB
testcase_07 AC 123 ms
27,236 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

/home/judge/data/code/Main.fs(14,9): warning FS0025: Incomplete pattern matches on this expression. For example, the value '[|_; _; _; _|]' may indicate a case not covered by the pattern(s).

ソースコード

diff #

// Learn more about F# at http://fsharp.org

open System

let max a b =
    if a > b then a else b

type S =
    { A: int
      B: int
      C: int }

let perm abc =
    let [| a; b; c |] = abc
    [| { A = a
         B = b
         C = c }
       { A = a
         B = c
         C = b }
       { A = b
         B = c
         C = a } |]

// x の上に y を置けるか
let fit (x: S) (y: S) = (x.A >= y.A && x.B >= y.B) || (x.A >= y.B && x.B >= y.A)

[<EntryPoint>]
let main argv =
    let n = stdin.ReadLine() |> int

    let rects =
        [| for i in 1 .. n -> stdin.ReadLine().Split() |> Array.map int |]
        |> Array.map perm

    let mutable dp = Array3D.create (1 <<< n) n 3 -1
    for i = 0 to (n - 1) do
        for j = 0 to 2 do
            dp.[1 <<< i, i, j] <- rects.[i].[j].C
    for (bits, i, j) in seq {
                            for bits in 0 .. ((1 <<< n) - 1) do
                                for i in 0 .. (n - 1) do
                                    for j in 0 .. 2 -> (bits, i, j)
                        } do
        for k = 0 to (n - 1) do
            if ((bits >>> k) &&& 1) = 0 then
                for l = 0 to 2 do
                    if fit rects.[i].[j] rects.[k].[l] then
                        dp.[bits ^^^ (1 <<< k), k, l] <- max dp.[bits ^^^ (1 <<< k), k, l]
                                                             (dp.[bits, i, j] + rects.[k].[l].C)
    dp
    |> Seq.cast
    |> Seq.max
    |> printfn "%d"
    0 // return an integer exit code
0