Please sign in first.
Submission #12068155
Source Code Expand
import Control.Exception (assert)
import Control.Monad
import qualified Control.Monad.ST as ST
import qualified Data.Array.IO as IO
import qualified Data.Array.ST as ST
import qualified Data.Array.Unboxed as A
import Data.Bits
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.Foldable
import Data.List
import Data.Maybe
import qualified Data.Sequence as Seq
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import Debug.Trace
readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine
type Edge = (Int, Int, Int)
eFrm (frm, _, _) = frm
eTo (_, to, _) = to
eCost (_, _, cost) = cost
shortestPath :: Int -> V.Vector Edge -> Int -> IO (Maybe (V.Vector Int))
shortestPath s edges numV = do
let numE = V.length edges
inf = 10^9 :: Int
d <- VM.new numV
VM.set d inf
VM.write d s 0
let loop :: Int -> IO Bool
loop i | i == numV = return True -- cyclic
| otherwise = do update <- loop2 0 False
if update
then loop (i+1)
else return False
loop2 :: Int -> Bool -> IO Bool
loop2 j upd | j == V.length edges = return upd
| otherwise = do
let e = edges V.! j
d_frm <- VM.read d (eFrm e)
d_to <- VM.read d (eTo e)
let ucond = d_frm /= inf && d_to > d_frm + eCost e
upd' = upd || ucond
when ucond $ VM.write d (eTo e) (d_frm + eCost e)
loop2 (j+1) upd'
cyc <- loop 0
res <- V.freeze d
if cyc
then return Nothing
else return (Just res)
main = do
[n, m, t] <- getIntList
as <- getIntVec n
edges <- V.replicateM m $ do
[a, b, c] <- getIntList
return (a-1, b-1, c)
let edges_rev = V.map (\(a, b, c) -> (b, a, c)) edges
costs <- fromJust <$> shortestPath 0 edges n
costs_r <- fromJust <$> shortestPath 0 edges_rev n
let solve i r | i >= n = r
| otherwise =
let waste = (costs V.! i) + (costs_r V.! i)
rest = max 0 (t - waste)
gain = rest * as V.! i
in solve (i+1) (max r gain)
print $ solve 0 0
Submission Info
| Submission Time | |
|---|---|
| Task | D - トレジャーハント |
| User | unnohideyuki |
| Language | Haskell (GHC 7.10.3) |
| Score | 50 |
| Code Size | 2922 Byte |
| Status | TLE |
| Exec Time | 3156 ms |
| Memory | 14204 KiB |
Judge Result
| Set Name | Sample | Subtask1 | All | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 50 / 50 | 0 / 50 | ||||||||
| Status |
|
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt |
| Subtask1 | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 50_small_01.txt, 50_small_02.txt, 50_small_03.txt, 50_small_04.txt, 50_small_05.txt, 50_small_06.txt, 50_small_07.txt, 50_small_08.txt, 50_small_09.txt, 50_small_10.txt, 60_hand_01.txt, 60_hand_02.txt, 60_hand_03.txt, 60_hand_04.txt, 70_max_01.txt, 70_max_02.txt, 70_max_03.txt |
| All | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 10_rand_01.txt, 10_rand_02.txt, 10_rand_03.txt, 10_rand_04.txt, 10_rand_05.txt, 10_rand_06.txt, 10_rand_07.txt, 10_rand_08.txt, 10_rand_09.txt, 10_rand_10.txt, 10_rand_12.txt, 10_rand_13.txt, 30_max_01.txt, 30_max_02.txt, 30_max_03.txt, 30_max_04.txt, 30_max_05.txt, 30_max_06.txt, 40_corner_01.txt, 40_corner_02.txt, 40_corner_03.txt, 40_corner_04.txt, 50_small_01.txt, 50_small_02.txt, 50_small_03.txt, 50_small_04.txt, 50_small_05.txt, 50_small_06.txt, 50_small_07.txt, 50_small_08.txt, 50_small_09.txt, 50_small_10.txt, 60_hand_01.txt, 60_hand_02.txt, 60_hand_03.txt, 60_hand_04.txt, 70_max_01.txt, 70_max_02.txt, 70_max_03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_example_01.txt | AC | 1 ms | 380 KiB |
| 00_example_02.txt | AC | 2 ms | 380 KiB |
| 00_example_03.txt | AC | 2 ms | 508 KiB |
| 10_rand_01.txt | AC | 4 ms | 1660 KiB |
| 10_rand_02.txt | AC | 23 ms | 2940 KiB |
| 10_rand_03.txt | AC | 5 ms | 2044 KiB |
| 10_rand_04.txt | AC | 3 ms | 1404 KiB |
| 10_rand_05.txt | AC | 5 ms | 2300 KiB |
| 10_rand_06.txt | AC | 5 ms | 2812 KiB |
| 10_rand_07.txt | AC | 6 ms | 3324 KiB |
| 10_rand_08.txt | AC | 3 ms | 1916 KiB |
| 10_rand_09.txt | AC | 6 ms | 3196 KiB |
| 10_rand_10.txt | AC | 3 ms | 1532 KiB |
| 10_rand_12.txt | AC | 39 ms | 4476 KiB |
| 10_rand_13.txt | AC | 40 ms | 4476 KiB |
| 30_max_01.txt | AC | 77 ms | 9084 KiB |
| 30_max_02.txt | AC | 129 ms | 10236 KiB |
| 30_max_03.txt | AC | 55 ms | 8060 KiB |
| 30_max_04.txt | AC | 53 ms | 8956 KiB |
| 30_max_05.txt | AC | 51 ms | 8956 KiB |
| 30_max_06.txt | AC | 53 ms | 8956 KiB |
| 40_corner_01.txt | TLE | 3156 ms | 14204 KiB |
| 40_corner_02.txt | TLE | 3155 ms | 14204 KiB |
| 40_corner_03.txt | TLE | 3156 ms | 12156 KiB |
| 40_corner_04.txt | TLE | 3156 ms | 12156 KiB |
| 50_small_01.txt | AC | 2 ms | 1020 KiB |
| 50_small_02.txt | AC | 2 ms | 508 KiB |
| 50_small_03.txt | AC | 2 ms | 636 KiB |
| 50_small_04.txt | AC | 2 ms | 1020 KiB |
| 50_small_05.txt | AC | 3 ms | 1148 KiB |
| 50_small_06.txt | AC | 3 ms | 1148 KiB |
| 50_small_07.txt | AC | 2 ms | 508 KiB |
| 50_small_08.txt | AC | 2 ms | 508 KiB |
| 50_small_09.txt | AC | 2 ms | 1020 KiB |
| 50_small_10.txt | AC | 2 ms | 892 KiB |
| 60_hand_01.txt | AC | 2 ms | 380 KiB |
| 60_hand_02.txt | AC | 2 ms | 380 KiB |
| 60_hand_03.txt | AC | 1 ms | 380 KiB |
| 60_hand_04.txt | AC | 2 ms | 380 KiB |
| 70_max_01.txt | AC | 18 ms | 2940 KiB |
| 70_max_02.txt | AC | 18 ms | 2940 KiB |
| 70_max_03.txt | AC | 18 ms | 2940 KiB |