結果
| 問題 |
No.120 傾向と対策:門松列(その1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-07-24 15:39:54 |
| 言語 | Haskell (9.10.1) |
| 結果 |
AC
|
| 実行時間 | 404 ms / 5,000 ms |
| コード長 | 581 bytes |
| コンパイル時間 | 8,138 ms |
| コンパイル使用メモリ | 173,440 KB |
| 実行使用メモリ | 58,112 KB |
| 最終ジャッジ日時 | 2024-06-23 05:42:19 |
| 合計ジャッジ時間 | 10,247 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) [2 of 2] Linking a.out
ソースコード
import Control.Applicative ((<$>))
import Control.Monad (replicateM)
import Data.List (sortBy, group)
main :: IO ()
main = do
t <- readLn
solve <$> replicateM t (getLine >> map read <$> words <$> getLine) >>= mapM_ print
solve :: [[Int]] -> [Int]
solve = map (f 0 . map length . group . sort)
where f ct xs | length xs < 3 = ct
| otherwise = let ss = sort xs
(as, bs) = splitAt 3 ss
in f (ct+1) ((filter (>0) . map (subtract 1)) as ++ bs)
sort :: [Int] -> [Int]
sort = sortBy (flip compare)