結果
| 問題 |
No.635 自然門松列
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2018-01-20 01:03:28 |
| 言語 | Haskell (9.10.1) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 650 ms |
| コード長 | 1,536 bytes |
| コンパイル時間 | 8,146 ms |
| コンパイル使用メモリ | 188,288 KB |
| 実行使用メモリ | 8,192 KB |
| 最終ジャッジ日時 | 2024-06-23 08:49:41 |
| 合計ジャッジ時間 | 6,357 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 23 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) [2 of 2] Linking a.out
ソースコード
import Control.Monad (replicateM)
import Debug.Trace
import Text.Printf
data Length = Short | Long
deriving (Eq, Show)
f x y x1 y1
| x < x1 = if y <= y1
then (Short, (0, 10000), Long, (10000, 10000))
else (Short, (0, t), Long, (t, 10000))
| x == x1 = if y < y1
then (Long, (0, 0), Short, (0, 10000))
else if y == y1
then (Short, (0, 0), Long, (0, 0))
else (Short, (0, 0), Long, (0, 10000))
| otherwise = if y < y1
then (Long, (0, t), Short, (t, 10000))
else (Long, (0, 10000), Short, (10000, 10000))
where
t = - (x - x1) / (y - y1)
-- [-, -)同士
intersect (a1, b1) (a2, b2) (x1, y1) (x2, y2) = a1 /= b1 && a2 /= b2 && not (b2 <= a1 || b1 <= a2) && (x1, y1) /= (x2, y2)
infix 0 ~=>
(~=>) a b = not a || b
-- [-, -)と(-, -]
intersect' (a1, b1) (a2, b2) (x1, y1) (x2, y2) = a1 /= b1 && a2 /= b2 && not (b2 < a1 || b1 <= a2) && (a1 == b2 ~=> (x1 + y1 * a1 - x2 + y2 * a1) <= 1e-8) && (x1, y1) /= (x2, y2)
main = do
n <- readLn
replicateM n $ do
[x2, x1, x3, y2, y1, y3] <- fmap (map ((fromIntegral :: Int -> Double) . read) . words) getLine
let (l1, r1, l2, r2) = f x2 y2 x1 y1
(l1', r1', l2', r2') = f x3 y3 x1 y1
can = if l1 == l1' then intersect r1 r1' (x2, y2) (x3, y3) || intersect r2 r2' (x2, y2) (x3, y3) else intersect' r1 r2' (x2, y2) (x3, y3) || intersect' r1' r2 (x2, y2) (x3, y3)
putStrLn $ if can then "YES" else "NO"
tottoripaper