結果
問題 |
No.504 ゲーム大会(ランキング)
|
ユーザー |
![]() |
提出日時 | 2017-09-03 01:45:39 |
言語 | Haskell (9.10.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 814 bytes |
コンパイル時間 | 2,303 ms |
コンパイル使用メモリ | 171,776 KB |
実行使用メモリ | 128,896 KB |
最終ジャッジ日時 | 2024-11-06 18:40:16 |
合計ジャッジ時間 | 5,993 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 5 TLE * 1 -- * 7 |
コンパイルメッセージ
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:27:15: warning: [GHC-63394] [-Wx-partial] In the use of ‘head’ (imported from Prelude, 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." | 27 | rank = (+1) . head . findIndices ((==0) . snd) . sortBy tupleComp . flip zip [0..] where | ^^^^ [2 of 2] Linking a.out
ソースコード
import Control.Monad (replicateM) import Control.Monad.State import Data.List (sortBy, findIndices) type Score = Int type Point = Int type Rank = Int main :: IO () main = do n <- readLn as <- replicateM n readLn mapM_ print $ evalState (solve n as 0) $ replicate n 0 solve :: Int -> [Score] -> Int -> State [Point] [Rank] solve n as t | t == n = return [] | otherwise = do pts <- get let npts = addIdx t (as!!t) pts put npts res <- solve n as (t+1) return $ rank npts : res rank :: [Point] -> Int rank = (+1) . head . findIndices ((==0) . snd) . sortBy tupleComp . flip zip [0..] where tupleComp (a,b) (c,d) | a == c = b `compare` d | otherwise = c `compare` a addIdx :: Int -> Int -> [Int] -> [Int] addIdx idx n xs = take idx xs ++ [xs!!idx+n] ++ drop (idx+1) xs