結果
| 問題 | No.2628 Shrinkage | 
| コンテスト | |
| ユーザー |  naut3 | 
| 提出日時 | 2024-02-16 21:49:07 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 4,544 bytes | 
| コンパイル時間 | 11,096 ms | 
| コンパイル使用メモリ | 393,884 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-09-28 20:03:15 | 
| 合計ジャッジ時間 | 12,072 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 1 WA * 27 | 
コンパイルメッセージ
warning: unused variable: `cx` --> src/main.rs:80:13 | 80 | let cx = (b1 * c2 - b2 * c1) as f64 / d as f64; | ^^ help: if this is intentional, prefix it with an underscore: `_cx` | = note: `#[warn(unused_variables)]` on by default warning: unused variable: `cy` --> src/main.rs:81:13 | 81 | let cy = (a2 * c1 - a1 * c2) as f64 / d as f64; | ^^ help: if this is intentional, prefix it with an underscore: `_cy`
ソースコード
#![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;
        }
        let e1 = b1 * c2 - b2 * c1;
        let e2 = a2 * c1 - a1 * c2;
        if d > 0 {
            if (e1 < X1 * d && X1 < x1) || (x1 < X1 && X1 * d < e1) {
                if (e1 < X2 * d && X2 < x2) || (x2 < X2 && X2 * d < e1) {
                    if (e2 < Y1 * d && Y1 < y1) || (y1 < Y1 && Y1 * d < e2) {
                        if (e2 < Y2 * d && Y2 < y2) || (y2 < Y2 && Y2 * d < e2) {
                            writeln!(out, "Yes");
                            return;
                        }
                    }
                }
            }
        } else {
            if (e1 > X1 * d && X1 < x1) || (x1 < X1 && X1 * d > e1) {
                if (e1 > X2 * d && X2 < x2) || (x2 < X2 && X2 * d > e1) {
                    if (e2 > Y1 * d && Y1 < y1) || (y1 < Y1 && Y1 * d > e2) {
                        if (e2 > Y2 * d && Y2 < y2) || (y2 < Y2 && Y2 * d > e2) {
                            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())
            }
        }
    }
}
            
            
            
        