結果
| 問題 |
No.2564 衝突予測
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-12-02 16:16:24 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 277 ms / 2,000 ms |
| コード長 | 1,844 bytes |
| コンパイル時間 | 12,484 ms |
| コンパイル使用メモリ | 377,980 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-26 20:04:19 |
| 合計ジャッジ時間 | 15,036 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 |
ソースコード
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) => unreachable!(),
(true, false) => y1 != y2 && (y2 > y1) == (vy1 > vy2),
(false, true) => x1 != x2 && (x2 > x1) == (vx1 > vx2),
(false, false) => {
if x1 == x2 || (x2 > x1) != (vx1 > vx2) || y1 == y2 || (y2 > y1) != (vy1 > vy2) {
return false;
}
(x2 - x1) * (vy1 - vy2) == (y2 - y1) * (vx1 - vx2)
}
}
}
fn velocity(d: char) -> (i64, i64) {
match d {
'R' => (1, 0),
'L' => (-1, 0),
'U' => (0, 1),
'D' => (0, -1),
_ => panic!(),
}
}