結果

問題 No.447 ゆきこーだーの雨と雪 (2)
ユーザー atuk721atuk721
提出日時 2017-02-13 05:30:06
言語 Haskell
(9.8.2)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 2,051 bytes
コンパイル時間 4,527 ms
コンパイル使用メモリ 199,688 KB
実行使用メモリ 20,088 KB
最終ジャッジ日時 2023-08-28 15:03:26
合計ジャッジ時間 7,456 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,548 KB
testcase_01 AC 3 ms
7,744 KB
testcase_02 AC 2 ms
7,576 KB
testcase_03 AC 32 ms
15,232 KB
testcase_04 AC 22 ms
13,728 KB
testcase_05 AC 42 ms
17,288 KB
testcase_06 AC 52 ms
16,796 KB
testcase_07 AC 43 ms
18,280 KB
testcase_08 AC 32 ms
14,632 KB
testcase_09 AC 42 ms
17,152 KB
testcase_10 AC 12 ms
12,480 KB
testcase_11 AC 32 ms
15,976 KB
testcase_12 AC 22 ms
14,540 KB
testcase_13 AC 42 ms
16,536 KB
testcase_14 AC 52 ms
19,064 KB
testcase_15 AC 32 ms
15,976 KB
testcase_16 AC 12 ms
12,240 KB
testcase_17 AC 32 ms
15,900 KB
testcase_18 AC 12 ms
12,612 KB
testcase_19 AC 52 ms
18,384 KB
testcase_20 AC 52 ms
19,132 KB
testcase_21 AC 22 ms
13,708 KB
testcase_22 AC 22 ms
15,280 KB
testcase_23 AC 42 ms
18,128 KB
testcase_24 AC 52 ms
19,792 KB
testcase_25 AC 62 ms
20,088 KB
testcase_26 AC 42 ms
18,492 KB
testcase_27 AC 42 ms
18,584 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import qualified Control.Monad as Mo
import qualified Control.Monad.State as S
import qualified Data.Char as C
import qualified Data.Ord as O
import qualified Data.List as L
import qualified Data.Map as M

type Order = M.Map String ([Int], [Int])
type Answer = M.Map Char Int
data ProcState = ProcState {order :: Order, answer :: Answer} deriving Show

main :: IO ()
main = do
  examN <- readLn :: IO Int
  levels <- fmap (map read . words) getLine :: IO [Int]
  submitN <- readLn :: IO Int
  submits <- fmap lines getContents

  let answers = M.fromList . zip (take examN ['A'..]) $ repeat 0
      resultS = Mo.forM (zip [1..] submits) $ \(count, submit) -> do
        s <- S.get
        let o = order s
            a = answer s
            [name, levelC:[]] = words submit
            (levelIndex, level) = getLevel levels levelC
            rank = (M.!) a levelC + 1
            score = floor $ 50 * (realToFrac level) + 50 * (realToFrac level) / (0.8 + 0.2 * (realToFrac rank))
            (scores, answers) = case M.lookup name o of
                                  Just (ss, as) -> (ss, as)
                                  Nothing -> (replicate examN 0, [])
            scores' = take levelIndex scores ++ (score : drop (levelIndex + 1) scores)
            o' = M.insert name (scores', count:answers) o
            a' = M.insert levelC rank a
        S.put $ ProcState o' a'

      result = M.toList . order . S.execState resultS $ ProcState M.empty answers
      result' = L.sortBy compareResult result

  Mo.forM_ (zip [1..] result') $ \(n, (name, (scores, _))) -> do
    putStrLn $ show n ++ " " ++ name ++ " " ++ (unwords $ map show scores) ++ " " ++ show (sum scores)

getLevel :: [Int] -> Char -> (Int, Int)
getLevel levels c = (index, levels !! index)
  where index = C.ord c - C.ord 'A'

compareResult :: (String, ([Int], [Int])) -> (String, ([Int], [Int])) -> Ordering
compareResult (_, (ss, o)) (_, (ss', o')) = if c /= EQ then c else O.comparing head o o'
                                          where c = O.comparing sum ss' ss
0