結果

問題 No.647 明太子
ユーザー ducktailducktail
提出日時 2018-02-09 23:14:11
言語 Haskell
(9.8.2)
結果
MLE  
実行時間 -
コード長 1,074 bytes
コンパイル時間 8,671 ms
コンパイル使用メモリ 180,904 KB
実行使用メモリ 812,928 KB
最終ジャッジ日時 2024-06-07 21:59:43
合計ジャッジ時間 21,075 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 18 ms
9,088 KB
testcase_10 AC 35 ms
12,800 KB
testcase_11 AC 8 ms
8,576 KB
testcase_12 AC 29 ms
11,776 KB
testcase_13 AC 67 ms
17,280 KB
testcase_14 AC 1,896 ms
131,712 KB
testcase_15 AC 103 ms
22,016 KB
testcase_16 AC 23 ms
10,624 KB
testcase_17 AC 2,457 ms
162,688 KB
testcase_18 AC 2,559 ms
173,952 KB
testcase_19 AC 26 ms
8,704 KB
testcase_20 AC 30 ms
8,320 KB
testcase_21 AC 12 ms
5,888 KB
testcase_22 MLE -
testcase_23 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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