結果
問題 | No.2628 Shrinkage |
ユーザー | naut3 |
提出日時 | 2024-02-16 21:44:46 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,947 bytes |
コンパイル時間 | 12,646 ms |
コンパイル使用メモリ | 401,984 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-09-28 19:58:04 |
合計ジャッジ時間 | 11,515 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,820 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
ソースコード
#![allow(non_snake_case, unused_imports, unused_must_use)] use std::io::{self, prelude::*, BufWriter, StdinLock, StdoutLock}; use std::str; fn main() { let (stdin, stdout) = (io::stdin(), io::stdout()); let mut scan = Scanner::new(stdin.lock()); let mut out = io::BufWriter::new(stdout.lock()); macro_rules! input { ($T: ty) => { scan.token::<$T>() }; ($T: ty, $N: expr) => { (0..$N).map(|_| scan.token::<$T>()).collect::<Vec<_>>() }; } let t = input!(usize); for _ in 0..t { solve(&mut scan, &mut out); } } fn solve(scan: &mut Scanner<StdinLock>, out: &mut BufWriter<StdoutLock>) { macro_rules! input { ($T: ty) => { scan.token::<$T>() }; ($T: ty, $N: expr) => { (0..$N).map(|_| scan.token::<$T>()).collect::<Vec<_>>() }; } let (x1, y1, x2, y2, X1, Y1, X2, Y2) = ( input!(isize), input!(isize), input!(isize), input!(isize), input!(isize), input!(isize), input!(isize), input!(isize), ); // (x1, y1), (X1, Y1) を通る直線の方程式と (x2, y2), (X2, Y2) を通る直線の方程式を求める // 交点 (cx, cy) が決まる(決まらないなら、一致させようがない) // (x1 < X1 < cx) or (cx < x1 < X1) みたいな位置関係でないなら一致できない? let is_parallel = { let a1 = Y1 - y1; let b1 = x1 - X1; let a2 = Y2 - y2; let b2 = x2 - X2; a1 * b2 - a2 * b1 == 0 }; if is_parallel { if (x1 < X1 && X1 < X2 && X2 < x2) || (x2 < X2 && X2 < X1 && X1 < x1) { if (y1 < Y1 && Y1 < Y2 && Y2 < y2) || (y2 < Y2 && Y2 < Y1 && Y1 < y1) { writeln!(out, "Yes"); return; } } writeln!(out, "No"); return; } else { let a1 = Y1 - y1; let b1 = x1 - X1; let a2 = Y2 - y2; let b2 = x2 - X2; let c1 = X1 * y1 - x1 * Y1; let c2 = X2 * y2 - x2 * Y2; let d = a1 * b2 - a2 * b1; let cx = (b1 * c2 - b2 * c1) as f64 / d as f64; let cy = (a2 * c1 - a1 * c2) as f64 / d as f64; // cx == X1 とか cy == Y1 とかだと一致できない if (b1 * c2 - b2 * c1) == X1 * d || (b1 * c2 - b2 * c1) == X2 * d { writeln!(out, "No"); return; } if (a2 * c1 - a1 * c2) == Y1 * d || (a2 * c1 - a1 * c2) == Y2 * d { writeln!(out, "No"); return; } if (cx < X1 as f64 && X1 < x1) || (x1 < X1 && (X1 as f64) < cx) { if (cx < X2 as f64 && X2 < x2) || (x2 < X2 && (X2 as f64) < cx) { if (cy < Y1 as f64 && Y1 < y1) || (y1 < Y1 && (Y1 as f64) < cy) { if (cy < Y2 as f64 && Y2 < y2) || (y2 < Y2 && (Y2 as f64) < cy) { writeln!(out, "Yes"); return; } } } } writeln!(out, "No"); } } struct Scanner<R> { reader: R, buf_str: Vec<u8>, buf_iter: str::SplitWhitespace<'static>, } impl<R: BufRead> Scanner<R> { fn new(reader: R) -> Self { Self { reader, buf_str: vec![], buf_iter: "".split_whitespace(), } } fn token<T: str::FromStr>(&mut self) -> T { loop { if let Some(token) = self.buf_iter.next() { return token.parse().ok().expect("Failed parse"); } self.buf_str.clear(); self.reader .read_until(b'\n', &mut self.buf_str) .expect("Failed read"); self.buf_iter = unsafe { let slice = str::from_utf8_unchecked(&self.buf_str); std::mem::transmute(slice.split_whitespace()) } } } }