結果
問題 | No.55 正方形を描くだけの簡単なお仕事です。 |
ユーザー |
![]() |
提出日時 | 2017-02-13 23:08:54 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 2,023 bytes |
コンパイル時間 | 12,278 ms |
コンパイル使用メモリ | 175,872 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-29 19:11:28 |
合計ジャッジ時間 | 13,182 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
コンパイルメッセージ
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:49:58: 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." | 49 | point = (\(Vector p) -> p) <$> ((vPlus <$> head <*> last) <$> find f2 vectors) | ^^^^ [2 of 2] Linking a.out
ソースコード
importControl.MonadreplicateMimportControl.Applicative(<$>),importData.Listnub,find,findIndexdata Point a = Point a aderivingEqinstanceShowa=>ShowPointawhereshow (Point x y) = show x ++ " " ++ show ydata Vector a = Vector (Point a)derivingEqmovePoint::Integrala=>Pointa->Vectora->PointamovePoint (Point x1 y1) (Vector (Point x2 y2)) = Point (x1 + x2) (y1 + y2)makeVectorP2P::Integrala=>Pointa->Pointa->VectoramakeVectorP2P (Point x1 y1) (Point x2 y2) = Vector (Point (x2 - x1) (y2 - y1))vSize::IntegralaFloatingb=>Vectora->bvSize (Vector (Point x y)) = sqrt $ fromIntegral (x ^ 2 + y ^ 2)vPlus::Integrala=>Vectora->Vectora->VectoravPlus (Vector (Point x1 y1)) (Vector (Point x2 y2)) = Vector (Point (x1 + x2) (y1 + y2))dotProd::Integrala=>Vectora->Vectora->adotProd (Vector (Point x1 y1)) (Vector (Point x2 y2)) = x1 * x2 + y1 * y2isVertical::Integrala=>Vectora->Vectora->BoolisVertical a b = dotProd a b == 0genPerm::Eqa=>Int->a->agenPerm n l = filter (\x -> nub x == x) $ replicateM n lsplitAt'::Int->a->asplitAt' n xs| length xs <= n = [xs]| otherwise = [fst xs'] ++ (splitAt' n $ snd xs')wherexs' = splitAt n xssolve::Integrala=>Pointa->Pointa->Pointa->MaybePointasolve p1 p2 p3 = answheref1 [p1, p2] = makeVectorP2P p1 p2f2 [v1, v2] = isVertical v1 v2 && vSize v1 == vSize v2vectors = splitAt' 2 $ map f1 $ genPerm 2 [p1, p2, p3]origin = (!!) <$> pure [p1, p2, p3] <*> findIndex f2 vectorspoint = (\(Vector p) -> p) <$> ((vPlus <$> head <*> last) <$> find f2 vectors)ans = movePoint <$> point <*> (Vector <$> origin)main = do[x1, y1, x2, y2, x3, y3] <- map read . words <$> getLinecase solve (Point x1 y1) (Point x2 y2) (Point x3 y3) ofJust p -> print pNothing -> print (-1)