結果
問題 | No.334 門松ゲーム |
ユーザー |
|
提出日時 | 2018-08-10 21:46:13 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 9 ms / 2,000 ms |
コード長 | 1,207 bytes |
コンパイル時間 | 9,636 ms |
コンパイル使用メモリ | 204,800 KB |
実行使用メモリ | 8,320 KB |
最終ジャッジ日時 | 2024-09-23 05:56:37 |
合計ジャッジ時間 | 10,787 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
コンパイルメッセージ
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:15:35: 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 | | otherwise = Just (head rs) | ^^^^ [2 of 2] Linking a.out
ソースコード
import Control.Applicative ((<$>), (<*>)) import Control.Monad (guard) import Data.Vector.Unboxed (Vector, (!), (//)) import qualified Data.Vector.Unboxed as V import Data.Maybe (catMaybes) main :: IO () main = solve <$> readLn <*> (V.fromList <$> map read <$> words <$> getLine) >>= putStrLn solve :: Int -> Vector Int -> String solve n ss = maybe "-1" (\(a, b, c) -> unwords . map show $ [a, b, c]) $ f n ss where f :: Int -> Vector Int -> Maybe (Int, Int, Int) f m v | null ls = Nothing | null rs = Nothing | otherwise = Just (head rs) where ls = do i <- [0..m-3] j <- [i+1..m-2] k <- [j+1..m-1] let ti = v ! i let tj = v ! j let tk = v ! k guard $ ti > 0 && tj > 0 && tk > 0 guard $ ti /= tk && (ti - tj) * (tk - tj) > 0 return (i, j, k) rs = catMaybes $ do (i, j, k) <- ls let nv = v // [(i,0),(j,0),(k,0)] case f m nv of Nothing -> return $ Just (i, j, k) Just _ -> return Nothing