結果

問題 No.92 逃走経路
ユーザー aimy
提出日時 2017-04-19 19:59:17
言語 Haskell
(9.10.1)
結果
TLE  
実行時間 -
コード長 1,040 bytes
コンパイル時間 7,618 ms
コンパイル使用メモリ 168,448 KB
実行使用メモリ 14,848 KB
最終ジャッジ日時 2024-07-19 09:30:59
合計ジャッジ時間 16,201 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 2
other TLE * 1 -- * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
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

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