結果

問題 No.452 横着者のビンゴゲーム
ユーザー okadukiokaduki
提出日時 2016-12-12 03:34:02
言語 Haskell
(9.8.2)
結果
AC  
実行時間 924 ms / 3,000 ms
コード長 1,395 bytes
コンパイル時間 9,653 ms
コンパイル使用メモリ 190,720 KB
実行使用メモリ 13,824 KB
最終ジャッジ日時 2024-05-07 01:53:58
合計ジャッジ時間 17,330 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 7 ms
7,808 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 8 ms
7,808 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 4 ms
5,888 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 213 ms
12,928 KB
testcase_15 AC 190 ms
12,672 KB
testcase_16 AC 116 ms
9,984 KB
testcase_17 AC 29 ms
7,808 KB
testcase_18 AC 86 ms
8,064 KB
testcase_19 AC 58 ms
8,192 KB
testcase_20 AC 40 ms
7,808 KB
testcase_21 AC 195 ms
8,832 KB
testcase_22 AC 34 ms
7,808 KB
testcase_23 AC 367 ms
11,136 KB
testcase_24 AC 28 ms
7,808 KB
testcase_25 AC 18 ms
7,808 KB
testcase_26 AC 217 ms
8,576 KB
testcase_27 AC 156 ms
8,192 KB
testcase_28 AC 97 ms
8,576 KB
testcase_29 AC 63 ms
8,064 KB
testcase_30 AC 254 ms
8,960 KB
testcase_31 AC 47 ms
8,064 KB
testcase_32 AC 28 ms
7,808 KB
testcase_33 AC 114 ms
8,064 KB
testcase_34 AC 102 ms
8,192 KB
testcase_35 AC 74 ms
7,936 KB
testcase_36 AC 22 ms
7,936 KB
testcase_37 AC 22 ms
7,808 KB
testcase_38 AC 924 ms
13,824 KB
testcase_39 AC 544 ms
9,984 KB
testcase_40 AC 548 ms
9,984 KB
testcase_41 AC 553 ms
9,856 KB
testcase_42 AC 553 ms
9,984 KB
testcase_43 AC 550 ms
9,856 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

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