結果

問題 No.1045 直方体大学
ユーザー ikdikd
提出日時 2020-05-03 02:12:16
言語 F#
(F# 4.0)
結果
TLE  
実行時間 -
コード長 1,559 bytes
コンパイル時間 3,953 ms
コンパイル使用メモリ 174,072 KB
実行使用メモリ 43,368 KB
最終ジャッジ日時 2023-08-30 18:01:17
合計ジャッジ時間 18,068 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
23,004 KB
testcase_01 AC 93 ms
23,196 KB
testcase_02 AC 93 ms
23,128 KB
testcase_03 AC 94 ms
25,236 KB
testcase_04 AC 94 ms
23,176 KB
testcase_05 AC 104 ms
25,180 KB
testcase_06 AC 103 ms
27,212 KB
testcase_07 AC 106 ms
27,204 KB
testcase_08 AC 967 ms
41,252 KB
testcase_09 AC 978 ms
39,248 KB
testcase_10 AC 963 ms
39,160 KB
testcase_11 AC 956 ms
41,376 KB
testcase_12 AC 987 ms
37,232 KB
testcase_13 AC 1,068 ms
41,380 KB
testcase_14 AC 969 ms
39,456 KB
testcase_15 AC 1,038 ms
37,128 KB
testcase_16 AC 1,034 ms
37,212 KB
testcase_17 AC 99 ms
25,236 KB
testcase_18 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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
        if dp.[bits, i, j] > 0 then
            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