結果

問題 No.2564 衝突予測
ユーザー atcoder8atcoder8
提出日時 2023-12-02 15:54:51
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,739 bytes
コンパイル時間 819 ms
コンパイル使用メモリ 169,920 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-02 15:54:55
合計ジャッジ時間 3,621 ms
ジャッジサーバーID
(参考情報)
judge9 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

fn main() {
    let t = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse::<usize>().unwrap()
    };

    for _ in 0..t {
        println!("{}", if solve() { "Yes" } else { "No" });
    }
}

fn solve() -> bool {
    let (x1, y1, d1) = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse::<i64>().unwrap(),
            iter.next().unwrap().parse::<i64>().unwrap(),
            iter.next().unwrap().parse::<char>().unwrap(),
        )
    };
    let (x2, y2, d2) = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse::<i64>().unwrap(),
            iter.next().unwrap().parse::<i64>().unwrap(),
            iter.next().unwrap().parse::<char>().unwrap(),
        )
    };

    let (vx1, vy1) = velocity(d1);
    let (vx2, vy2) = velocity(d2);

    if x1 != x2 && vx1 == vx2 {
        return false;
    }

    if y1 != y2 && vy1 == vy2 {
        return false;
    }

    match (vx1 == vx2, vy1 == vy2) {
        (true, true) => false,
        (true, false) => (y2 - y1) / (vy1 - vy2) > 0,
        (false, true) => (x2 - x1) / (vx1 - vx2) > 0,
        (false, false) => {
            let tx = (x2 - x1) / (vx1 - vx2);
            let ty = (y2 - y1) / (vy1 - vy2);

            tx > 0 && tx == ty
        }
    }
}

fn velocity(d: char) -> (i64, i64) {
    match d {
        'R' => (1, 0),
        'L' => (-1, 0),
        'U' => (0, 1),
        'D' => (0, -1),
        _ => panic!(),
    }
}
0