結果

問題 No.452 横着者のビンゴゲーム
ユーザー okadukiokaduki
提出日時 2016-12-12 03:34:52
言語 Haskell
(9.6.2)
結果
AC  
実行時間 942 ms / 3,000 ms
コード長 1,422 bytes
コンパイル時間 1,045 ms
コンパイル使用メモリ 176,828 KB
実行使用メモリ 18,008 KB
最終ジャッジ日時 2023-08-19 18:58:47
合計ジャッジ時間 9,242 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,232 KB
testcase_01 AC 3 ms
7,280 KB
testcase_02 AC 3 ms
7,348 KB
testcase_03 AC 9 ms
11,332 KB
testcase_04 AC 3 ms
7,564 KB
testcase_05 AC 12 ms
11,352 KB
testcase_06 AC 3 ms
7,352 KB
testcase_07 AC 4 ms
7,984 KB
testcase_08 AC 5 ms
9,292 KB
testcase_09 AC 3 ms
7,296 KB
testcase_10 AC 3 ms
7,620 KB
testcase_11 AC 5 ms
8,812 KB
testcase_12 AC 3 ms
7,564 KB
testcase_13 AC 3 ms
7,276 KB
testcase_14 AC 212 ms
17,056 KB
testcase_15 AC 202 ms
17,020 KB
testcase_16 AC 123 ms
14,412 KB
testcase_17 AC 42 ms
11,504 KB
testcase_18 AC 92 ms
12,400 KB
testcase_19 AC 72 ms
11,712 KB
testcase_20 AC 42 ms
11,584 KB
testcase_21 AC 212 ms
13,384 KB
testcase_22 AC 42 ms
11,496 KB
testcase_23 AC 372 ms
13,796 KB
testcase_24 AC 32 ms
11,476 KB
testcase_25 AC 22 ms
11,364 KB
testcase_26 AC 233 ms
12,780 KB
testcase_27 AC 162 ms
12,272 KB
testcase_28 AC 102 ms
12,344 KB
testcase_29 AC 73 ms
11,780 KB
testcase_30 AC 262 ms
13,400 KB
testcase_31 AC 52 ms
11,724 KB
testcase_32 AC 32 ms
11,424 KB
testcase_33 AC 122 ms
11,976 KB
testcase_34 AC 112 ms
12,232 KB
testcase_35 AC 82 ms
11,760 KB
testcase_36 AC 33 ms
11,516 KB
testcase_37 AC 32 ms
11,420 KB
testcase_38 AC 942 ms
18,008 KB
testcase_39 AC 573 ms
14,484 KB
testcase_40 AC 572 ms
14,432 KB
testcase_41 AC 573 ms
14,428 KB
testcase_42 AC 573 ms
14,440 KB
testcase_43 AC 572 ms
14,528 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Data.Array
import Debug.Trace
import Data.List(sort)

readInts :: B.ByteString -> [Int]
readInts = map (fst . fromJust . B.readInt) . B.words

getInts :: IO [Int]
getInts = liftM readInts B.getLine

getCol arr n m x = sort [arr!(m,y,x) | y <- [1..n]]
getRow arr n m y = sort [arr!(m,y,x) | x <- [1..n]]
getDiag arr n m = [sort [arr!(m,i,i) | i <- [1..n]],
                    sort [arr!(m,n+1-i,i) | i <- [1..n]]]

calc ss n m1 m2 = minimum [f n n 0 s1 s2 |
                           s1 <- ss!m1,
                           s2 <- ss!m2]
  where
    f i j acc [] _ = acc+j
    f i j acc _ [] = acc+i
    f i j acc (x:xs) (y:ys)
      | x < y  = f (i-1) j (acc+1) xs (y:ys)
      | x > y  = f i (j-1) (acc+1) (x:xs) ys
      | x == y = f (i-1) (j-1) (acc+1) xs ys

build arr n m = [(i,xs) | i <- [1..m],
                  let xs = [getCol arr n i x | x <- [1..n]]
                           ++ [getRow arr n i y | y <- [1..n]]
                           ++ getDiag arr n i]

main = do
  [n,m] <- getInts
  arr <- array ((1,1,1),(m,n,n)) <$> concat <$>
    forM [1..m] (\k -> concat <$>
                       forM [1..n] (\i -> zip [(k,i,j) | j <- [1..n]] <$> getInts))
  let ss = array (1,m) $ build arr n m
  let ans = minimum [calc ss n m1 m2 | m1 <- [1..m], m2 <- [m1+1..m]]
  print $ ans-1
0