結果

問題 No.504 ゲーム大会(ランキング)
ユーザー Asdf_QwertyZAsdf_QwertyZ
提出日時 2017-09-03 01:45:39
言語 Haskell
(9.8.2)
結果
TLE  
実行時間 -
コード長 814 bytes
コンパイル時間 1,836 ms
コンパイル使用メモリ 170,880 KB
実行使用メモリ 131,712 KB
最終ジャッジ日時 2024-04-24 10:58:45
合計ジャッジ時間 5,486 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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

ソースコード

diff #

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
0