結果

問題 No.647 明太子
ユーザー ducktail
提出日時 2018-02-09 23:14:11
言語 Haskell
(9.10.1)
結果
TLE  
実行時間 -
コード長 1,074 bytes
コンパイル時間 9,106 ms
コンパイル使用メモリ 180,916 KB
実行使用メモリ 816,896 KB
最終ジャッジ日時 2024-12-26 08:00:09
合計ジャッジ時間 25,379 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 19 TLE * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )

Main.hs:21:33: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘head’
    (imported from Data.List, but defined in GHC.List):
    "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
   |
21 |     sls = map (\p -> (length p, head p)) . group . sort $ ls
   |                                 ^^^^
[2 of 2] Linking a.out

ソースコード

diff #

import Control.Monad (replicateM)
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Char (isSpace)

main :: IO ()
main = do
  n <- getl $ readi B.readInt
  abs <- replicateM n (getl $ readil B.readInt)
  m <- getl $ readi B.readInt
  xys <- replicateM m (getl $ readil B.readInt)
  mapM_ print $ solve abs xys

solve :: [[Int]] -> [[Int]] -> [Int]
solve abs xys
  | null ls = [0]
  | otherwise = mls
  where
    ls = [i | [a, b] <- abs, (i, [x, y]) <- zip [1..] xys, a >= x && b <= y]
    sls = map (\p -> (length p, head p)) . group . sort $ ls
    mxl = maximum . map fst $ sls
    mls = sort $ map snd $ filter (\q -> fst q == mxl) sls

getl :: (ByteString -> a) -> IO a
getl f = f <$> B.getLine

readi :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> a
readi f s = let Just (n, _) = f s in n

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr g
  where
    g s = do
      (n, s') <- f s
      return (n, B.dropWhile isSpace s')
0