結果

問題 No.135 とりあえず1次元の問題
ユーザー ducktailducktail
提出日時 2018-01-06 22:21:42
言語 Haskell
(9.8.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 646 bytes
コンパイル時間 1,086 ms
コンパイル使用メモリ 144,384 KB
最終ジャッジ日時 2023-11-26 02:02:59
合計ジャッジ時間 1,806 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )

Main.hs:8:1: error:
    Could not load module ‘Data.Set’
    It is a member of the hidden package ‘containers-0.6.7’.
    You can run ‘:set -package containers’ to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
8 | import Data.Set (Set)
  | ^^^^^^^^^^^^^^^^^^^^^

Main.hs:9:1: error:
    Could not load module ‘Data.Set’
    It is a member of the hidden package ‘containers-0.6.7’.
    You can run ‘:set -package containers’ to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
9 | import qualified Data.Set as S
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ソースコード

diff #

import Control.Applicative ((<$>))
import Control.Monad
import Data.List

import Data.Char (isSpace)
import qualified Data.ByteString.Char8 as B8

import Data.Set (Set)
import qualified Data.Set as S

main :: IO ()
main = do
  B8.getLine
  solve <$> readIntList >>= print

solve :: [Int] -> Int
solve xs = let s = foldl' f S.empty xs
           in if S.size s == 1 then 0 else fst . S.foldl' g (10000000, -10000000) $ s
  where
    f s x = S.insert x s
    g (d, x) y = (min d (y - x), y)

readIntList :: IO [Int]
readIntList = unfoldr f <$> B8.getLine
  where
    f s = do
      (n, s') <- B8.readInt s
      return (n, B8.dropWhile isSpace s')
0