結果
問題 | No.185 和風 |
ユーザー | はむ吉🐹 |
提出日時 | 2016-06-06 22:35:42 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 3 ms / 1,000 ms |
コード長 | 697 bytes |
コンパイル時間 | 3,919 ms |
コンパイル使用メモリ | 182,524 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-08 16:46:34 |
合計ジャッジ時間 | 4,523 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 3 ms
5,248 KB |
コンパイルメッセージ
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:7:25: 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." | 7 | allTheSame xs = all (== head xs) $ tail xs | ^^^^ Main.hs:7:36: warning: [GHC-63394] [-Wx-partial] In the use of ‘tail’ (imported from Prelude, but defined in GHC.List): "This is a partial function, it throws an error on empty lists. Replace it with drop 1, or use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty." | 7 | allTheSame xs = all (== head xs) $ tail xs | ^^^^ Main.hs:15:16: 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." | 15 | ans1 = head anss | ^^^^ [2 of 2] Linking a.out
ソースコード
import qualified Data.ByteString.Lazy.Char8 as LC import Data.Maybe (fromJust) type Equation a = (a, a) allTheSame :: (Eq a) => [a] -> Bool allTheSame xs = all (== head xs) $ tail xs solve :: Integral a => [Equation a] -> a solve xs | allTheSame anss && ans1 > 0 = ans1 | otherwise = -1 where anss = fmap (\(x, y) -> y - x) xs ans1 = head anss tuplify2 :: [a] -> (a, a) tuplify2 [x, y] = (x, y) tuplify2 _ = error "the length of the list must be two" unsafeReadInt :: LC.ByteString -> Int unsafeReadInt = fst . fromJust . LC.readInt main :: IO () main = getLine >> LC.getContents >>= print . solve . fmap (tuplify2 . fmap unsafeReadInt . LC.words) . LC.lines