結果

問題 No.506 限られたジャパリまん
ユーザー aimyaimy
提出日時 2017-07-07 13:32:56
言語 Haskell
(9.8.2)
結果
AC  
実行時間 702 ms / 2,000 ms
コード長 1,000 bytes
コンパイル時間 5,557 ms
コンパイル使用メモリ 179,348 KB
実行使用メモリ 13,504 KB
最終ジャッジ日時 2023-09-10 12:55:05
合計ジャッジ時間 5,994 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,484 KB
testcase_01 AC 3 ms
7,500 KB
testcase_02 AC 5 ms
8,536 KB
testcase_03 AC 3 ms
7,468 KB
testcase_04 AC 22 ms
12,980 KB
testcase_05 AC 6 ms
10,260 KB
testcase_06 AC 3 ms
7,632 KB
testcase_07 AC 22 ms
12,396 KB
testcase_08 AC 652 ms
13,504 KB
testcase_09 AC 213 ms
13,008 KB
testcase_10 AC 12 ms
11,688 KB
testcase_11 AC 702 ms
13,300 KB
testcase_12 AC 403 ms
12,812 KB
testcase_13 AC 3 ms
7,580 KB
testcase_14 AC 13 ms
11,876 KB
testcase_15 AC 3 ms
7,948 KB
testcase_16 AC 452 ms
13,260 KB
testcase_17 AC 32 ms
12,268 KB
testcase_18 AC 32 ms
12,124 KB
testcase_19 AC 72 ms
11,936 KB
testcase_20 AC 193 ms
13,104 KB
testcase_21 AC 62 ms
13,100 KB
testcase_22 AC 233 ms
13,036 KB
testcase_23 AC 152 ms
12,840 KB
testcase_24 AC 23 ms
12,072 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 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 (mod nmax modulo)
 if nmax == 0
  then return ()
  else mapM_ (putStrLn . snd) ps

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

modulo = 10^9+7

(!?) 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