結果

問題 No.2564 衝突予測
コンテスト
ユーザー atcoder8
提出日時 2023-12-02 15:45:34
言語 Rust
(1.94.0 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
WA  
実行時間 -
コード長 1,475 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,154 ms
コンパイル使用メモリ 185,580 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-13 19:49:22
合計ジャッジ時間 4,277 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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(),
        )
    };

    if d1 == d2 {
        return false;
    }

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

    (x1 == x2 && vx1 == vx2 || vx1 != vx2 && (x2 - x1) / (vx1 - vx2) > 0)
        && (y1 == y2 && vy1 == vy2 || vy1 != vy2 && (y2 - y1) / (vy1 - vy2) > 0)
}

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