結果

問題 No.92 逃走経路
ユーザー aimyaimy
提出日時 2017-04-19 19:59:17
言語 Haskell
(9.8.2)
結果
TLE  
実行時間 -
コード長 1,040 bytes
コンパイル時間 4,803 ms
コンパイル使用メモリ 160,748 KB
実行使用メモリ 21,236 KB
最終ジャッジ日時 2023-09-26 15:23:50
合計ジャッジ時間 17,563 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Monad

type YukiCity = ([City],[Road])
cities = fst
roads = snd

type Road = (Path,Toll)
path = fst
toll = snd

type Path = (City,City)
link c (c1,c2) = c==c1 || c==c2
from c (c1,c2)
 | c == c1 = c2
 | c == c2 = c1

type Info = [Toll]
type City = Int
type Toll = Int

main = do
 [n,m,k] <- map read . words <$> getLine
 abcs <- map (map read . words) <$> replicateM m getLine
 let rs = map (\[a,b,c] -> ((a,b),c)) abcs
 info <- map read . words <$> getLine
 let result = investigate ([1..n],rs) (reverse info)
 print (length result)
 putStrLn (unwords (map show result))

investigate :: YukiCity -> Info -> [City]
investigate yc i = filter (suspicion (roads yc) i) (cities yc)

suspicion :: [Road] -> Info -> City -> Bool
suspicion rs i = not . null . filter ((== length i) . length) . routeFrom rs i

routeFrom :: [Road] -> Info -> City -> [[City]]
routeFrom _ [] _ = [[]]
routeFrom rs (i':i) c = do
 r <- rs
 guard (link c (path r))
 guard (toll r == i')
 let c' = from c (path r)
 cs' <- routeFrom rs i c'
 return (c':cs')
0