Submission #35932327


Source Code Expand

Copy
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List
import qualified Data.IntMap as M
-- import Data.Ratio
main = do
[n,a] <- bsGetLnInts
wxvs <- replicateM n bsGetLnInts
let ans = abc274f n a wxvs
print ans
bsGetLnInts :: IO [Int]
bsGetLnInts = BS.getLine >>= return . unfoldr (BS.readInt . BS.dropWhile isSpace)
abc274f :: Int -> Int -> [[Int]] -> Int
abc274f n a wxvs = maximum $ map (score a wxvs) wxvs
score a wxvs (wi:xi:vi:_) =
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List

import qualified Data.IntMap as M
-- import Data.Ratio

main = do
  [n,a] <- bsGetLnInts
  wxvs <- replicateM n bsGetLnInts
  let ans = abc274f n a wxvs
  print ans

bsGetLnInts :: IO [Int]
bsGetLnInts = BS.getLine >>= return . unfoldr (BS.readInt . BS.dropWhile isSpace)

abc274f :: Int -> Int -> [[Int]] -> Int
abc274f n a wxvs = maximum $ map (score a wxvs) wxvs

score a wxvs (wi:xi:vi:_) =
--    maximum $ loop 0 $ M.assocs twm
    maximum $ map snd $ dropWhile ((0 >) . fst) $ scanl1 add $ M.assocs twm
  where
    twm = M.fromListWith (+) -- addp
          [ tw
          | (wj:xj:vj:_) <- wxvs
          , tw <- spike (vj - vi) (xj - xi) wj
          ]
    spike uj yj wj =
      case compare uj 0 of
        LT -> [(ta, wj), (succ t0, -wj)]
        EQ -> [(0 % 1, wj) | 0 <= yj, yj <= a]
        GT -> [(t0, wj), (succ ta, -wj)]
      where
        m1 = -1 % 1
        t0 = let t = (0 - yj) % uj in if t < 0 then m1 else t
        ta = let t = (a - yj) % uj in if t < 0 then m1 else t
    add (_,acc) (t,d) = let acc1 = acc + d in acc1 `seq` (t, acc1)
--    addp (a,b) (c,d) = (a+c, b+d)
{-
    loop _ [] = []
    loop acc ((t, (wp,wm)):twms)
      | t < 0 =        loop acc2 twms
      | True  = acc1 : loop acc2 twms
      where
        acc1 = acc  + wp
        acc2 = acc1 - wm
-}
-- (%) :: Int -> Int -> Double
-- m % n = fromIntegral m / fromIntegral n

(%) :: Int -> Int -> Int
m % n = div (10^9 * m) n

-- IntMap delta=succ

Submission Info

Submission Time
Task F - Fishing
User joetheshootingst
Language Haskell (GHC 8.8.3)
Score 500
Code Size 1597 Byte
Status AC
Exec Time 2105 ms
Memory 7784 KB

Compile Error

Loaded package environment from /home/contestant/.ghc/x86_64-linux-8.8.3/environments/default

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 23
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 6 ms 3620 KB
random_02.txt AC 215 ms 5304 KB
random_03.txt AC 2078 ms 7556 KB
random_04.txt AC 238 ms 5940 KB
random_05.txt AC 1923 ms 7108 KB
random_06.txt AC 50 ms 4844 KB
random_07.txt AC 2105 ms 7644 KB
random_08.txt AC 895 ms 6624 KB
random_09.txt AC 1967 ms 6916 KB
random_10.txt AC 33 ms 4776 KB
random_11.txt AC 2090 ms 7640 KB
random_12.txt AC 35 ms 4920 KB
random_13.txt AC 1979 ms 6884 KB
random_14.txt AC 424 ms 6204 KB
random_15.txt AC 2074 ms 7544 KB
random_16.txt AC 11 ms 4780 KB
random_17.txt AC 1362 ms 7628 KB
random_18.txt AC 1329 ms 7552 KB
random_19.txt AC 1328 ms 7604 KB
random_20.txt AC 1229 ms 7784 KB
sample_01.txt AC 2 ms 3660 KB
sample_02.txt AC 2 ms 3648 KB
sample_03.txt AC 2 ms 3732 KB


2025-04-21 (Mon)
18:26:18 +00:00