結果

問題 No.231 めぐるはめぐる (1)
ユーザー ducktailducktail
提出日時 2018-02-03 15:00:48
言語 Haskell
(9.8.2)
結果
AC  
実行時間 4 ms / 1,000 ms
コード長 974 bytes
コンパイル時間 2,826 ms
コンパイル使用メモリ 163,016 KB
実行使用メモリ 7,860 KB
最終ジャッジ日時 2023-09-02 08:26:23
合計ジャッジ時間 3,380 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,860 KB
testcase_01 AC 3 ms
7,172 KB
testcase_02 AC 3 ms
7,092 KB
testcase_03 AC 4 ms
7,804 KB
testcase_04 AC 4 ms
7,784 KB
testcase_05 AC 3 ms
7,384 KB
testcase_06 AC 3 ms
7,652 KB
testcase_07 AC 3 ms
7,220 KB
testcase_08 AC 3 ms
7,364 KB
testcase_09 AC 2 ms
7,000 KB
testcase_10 AC 3 ms
6,988 KB
testcase_11 AC 2 ms
7,032 KB
testcase_12 AC 3 ms
7,532 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 Control.Applicative ((<$>))
import Control.Monad (replicateM)

import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B

import Data.List
import Data.Function (on, fix)

import Data.Char (isSpace)

main :: IO ()
main = do
  n <- getl (readi B.readInt)
  solve n <$> replicateM n (getl $ readil B.readInt) >>= mapM_ putStrLn

solve :: Int -> [[Int]] -> [String]
solve n =  f1 . maximumBy (compare `on` snd) . zip [1..n] . map f2
  where
    f1 (x, y)
      | 6 * y >= 3000000 = "YES" : replicate 6 (show x)
      | otherwise = ["NO"]
    f2 [g, d] = g - 30000 * d
    

getl :: (ByteString -> a) -> IO a
getl f = f <$> B.getLine

readi :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> a
readi f s = let Just (n, _) = f s in n

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr g
  where
    g s = do
      (n, s') <- f s
      return (n, B.dropWhile isSpace s')
0