結果

問題 No.2564 衝突予測
ユーザー Kyo_s_sKyo_s_s
提出日時 2023-11-18 16:16:44
言語 Rust
(1.77.0)
結果
AC  
実行時間 222 ms / 2,000 ms
コード長 4,276 bytes
コンパイル時間 11,769 ms
コンパイル使用メモリ 167,392 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2023-11-23 14:03:13
合計ジャッジ時間 4,451 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,548 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 AC 221 ms
6,548 KB
testcase_04 AC 221 ms
6,548 KB
testcase_05 AC 221 ms
6,548 KB
testcase_06 AC 221 ms
6,548 KB
testcase_07 AC 221 ms
6,548 KB
testcase_08 AC 222 ms
6,548 KB
testcase_09 AC 221 ms
6,548 KB
testcase_10 AC 220 ms
6,548 KB
testcase_11 AC 221 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
    input! {
        t: usize,
        query: [(i64, i64, char, i64, i64, char); t],
    }

    for i in 0..t {
        let (x1, y1, d1, x2, y2, d2) = query[i];
        if d1 == d2 {
            println!("No");
            continue;
        }

        let (mut x1, mut y1, mut x2, mut y2) = (x1 - x1, y1 - y1, x2 - x1, y2 - y1);

        if (d1, d2) == ('R', 'L') || (d1, d2) == ('L', 'R') {
            if (d1, d2) == ('L', 'R') {
                // (x1, y1, x2, y2) = (x2, y2, x1, y1);
                std::mem::swap(&mut x1, &mut x2);
                std::mem::swap(&mut y1, &mut y2);
            }
            if y1 == y2 && x1 < x2 {
                println!("Yes");
            } else {
                println!("No");
            }
            continue;
        }

        if (d1, d2) == ('U', 'D') || (d1, d2) == ('D', 'U') {
            if (d1, d2) == ('D', 'U') {
                // (x1, y1, x2, y2) = (x2, y2, x1, y1);
                std::mem::swap(&mut x1, &mut x2);
                std::mem::swap(&mut y1, &mut y2);
            }
            if x1 == x2 && y1 < y2 {
                println!("Yes");
            } else {
                println!("No");
            }
            continue;
        }

        if (d1, d2) == ('U', 'R') || (d1, d2) == ('R', 'U') {
            if (d1, d2) == ('R', 'U') {
                // (x1, y1, x2, y2) = (x2, y2, x1, y1);
                std::mem::swap(&mut x1, &mut x2);
                std::mem::swap(&mut y1, &mut y2);
            }
            let dist1 = y2 - y1;
            let dist2 = x1 - x2;
            if dist1 == dist2 && dist1 > 0 {
                println!("Yes");
            } else {
                println!("No");
            }
            continue;
        }
        if (d1, d2) == ('U', 'L') || (d1, d2) == ('L', 'U') {
            if (d1, d2) == ('L', 'U') {
                // (x1, y1, x2, y2) = (x2, y2, x1, y1);
                std::mem::swap(&mut x1, &mut x2);
                std::mem::swap(&mut y1, &mut y2);
            }
            let dist1 = y2 - y1;
            let dist2 = x2 - x1;
            if dist1 == dist2 && dist1 > 0 {
                println!("Yes");
            } else {
                println!("No");
            }
            continue;
        }
        if (d1, d2) == ('D', 'R') || (d1, d2) == ('R', 'D') {
            if (d1, d2) == ('R', 'D') {
                // (x1, y1, x2, y2) = (x2, y2, x1, y1);
                std::mem::swap(&mut x1, &mut x2);
                std::mem::swap(&mut y1, &mut y2);
            }
            let dist1 = y1 - y2;
            let dist2 = x1 - x2;
            if dist1 == dist2 && dist1 > 0 {
                println!("Yes");
            } else {
                println!("No");
            }
            continue;
        }
        if (d1, d2) == ('D', 'L') || (d1, d2) == ('L', 'D') {
            if (d1, d2) == ('L', 'D') {
                // (x1, y1, x2, y2) = (x2, y2, x1, y1);
                std::mem::swap(&mut x1, &mut x2);
                std::mem::swap(&mut y1, &mut y2);
            }
            let dist1 = y1 - y2;
            let dist2 = x2 - x1;
            if dist1 == dist2 && dist1 > 0 {
                println!("Yes");
            } else {
                println!("No");
            }
            continue;
        }

        println!("No");
    }
}
0