結果

問題 No.628 Tagの勢い
ユーザー ducktailducktail
提出日時 2018-01-05 22:53:12
言語 Haskell
(9.8.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 761 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 146,688 KB
最終ジャッジ日時 2024-04-16 20:01:14
合計ジャッジ時間 483 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
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:4:1: error: [GHC-87110]
    Could not load module ‘Data.Map’.
    It is a member of the hidden package ‘containers-0.6.8’.
    Use -v to see a list of the files searched for.
  |
4 | import Data.Map (Map)
  | ^^^^^^^^^^^^^^^^^^^^^

Main.hs:5:1: error: [GHC-87110]
    Could not load module ‘Data.Map’.
    It is a member of the hidden package ‘containers-0.6.8’.
    Use -v to see a list of the files searched for.
  |
5 | import qualified Data.Map as M
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ソースコード

diff #

import Control.Applicative ((<$>))
import Control.Monad (replicateM, mapM_)
import Data.List
import Data.Map (Map)
import qualified Data.Map as M

main :: IO ()
main = do
  n <- getl read :: IO Int
  solve <$> replicateM n readInfo >>= mapM_ printTag
  where
    printTag :: (String, Int) -> IO ()
    printTag (t, p) = putStrLn $ t ++ " " ++ show p

solve :: [[(String, Int)]] -> [(String, Int)]
solve xs = take 10 $ sortBy f $ M.toList mp
  where mp = M.fromListWith (+) (concat xs)
        f (ta, pa) (tb, pb) = if pa == pb then compare ta tb else compare pb pa

getl :: (String -> a) -> IO a
getl f = f <$> getLine

readInfo :: IO [(String, Int)]
readInfo = do
  getLine
  [_, p] <- getl (map read . words)
  tgs <- getl words
  return $ zip tgs (repeat p)
0