結果

問題 No.506 限られたジャパリまん
ユーザー aimyaimy
提出日時 2017-07-07 13:23:49
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 985 bytes
コンパイル時間 4,923 ms
コンパイル使用メモリ 180,348 KB
実行使用メモリ 13,548 KB
最終ジャッジ日時 2023-09-10 12:54:57
合計ジャッジ時間 10,013 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,424 KB
testcase_01 AC 3 ms
7,392 KB
testcase_02 AC 4 ms
8,584 KB
testcase_03 AC 2 ms
7,396 KB
testcase_04 WA -
testcase_05 AC 6 ms
10,176 KB
testcase_06 AC 3 ms
7,540 KB
testcase_07 WA -
testcase_08 AC 713 ms
13,424 KB
testcase_09 AC 232 ms
13,064 KB
testcase_10 AC 12 ms
11,668 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 3 ms
7,540 KB
testcase_14 WA -
testcase_15 AC 3 ms
8,052 KB
testcase_16 AC 492 ms
12,684 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 qualified Data.Map as M
import Data.List
import Control.Monad

japari h w (ps,rs) = (n, (ps,rs))
 where
  n = jmap !? (h-1,w-1)
  jmap = makeMap h w (map fst rs)

comb :: Int -> [a] -> [[a]]
comb 0 _ = [[]]
comb _ [] = []
comb n (x:xs) = [x:y | y <- comb (n-1) xs] ++ comb n xs 

main = do
 [w,h,k,p] <- map read . words <$> getLine
 friends <- map (readFriends . words) <$> replicateM k getLine
 let pass = comb p friends
 let rest = map (friends \\) pass
 let combs = zip pass rest
 let (nmax,(ps,_)) = maximum (map (japari (h+1) (w+1)) combs)
 print nmax
 mapM_ (putStrLn . snd) ps

readFriends [x,y,n] = ((read y, read x), n)

modulo = 10^9+7
(+%) x y = mod (x + y) modulo

(!?) im (i,j)
 | i<0 || j<0 = 0
 | otherwise = im M.! (i,j)

makeMap h w fs = foldl' (asum fs) M.empty [(i,j) | i<-[0..h-1], j<-[0..w-1]]

asum fs acc pos@(i,j)
 | pos == (0,0) = M.insert pos 1 acc
 | elem pos fs = M.insert pos 0 acc
 | otherwise = M.insert pos ((acc!?(i-1,j)) +% (acc!?(i,j-1))) acc
0