結果
| 問題 |
No.2353 Guardian Dogs in Spring
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-16 23:20:59 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 2,000 ms |
| コード長 | 2,251 bytes |
| コンパイル時間 | 14,264 ms |
| コンパイル使用メモリ | 385,524 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-24 16:32:42 |
| 合計ジャッジ時間 | 20,662 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 40 |
ソースコード
use amplitude::Amplitude;
fn main() {
let n = {
let mut line = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.trim().parse::<usize>().unwrap()
};
let xy: Vec<_> = (0..n)
.map(|_| {
let mut line = String::new();
std::io::stdin().read_line(&mut line).unwrap();
let mut iter = line.split_whitespace();
(
iter.next().unwrap().parse::<usize>().unwrap(),
iter.next().unwrap().parse::<usize>().unwrap(),
)
})
.collect();
let mut amplitudes: Vec<_> = xy
.iter()
.enumerate()
.map(|(i, &(x, y))| (Amplitude::new(x, y), i))
.collect();
amplitudes.sort_unstable_by_key(|x| x.0);
let mut ans = vec![];
for i in (0..(n - 1)).step_by(2) {
ans.push((amplitudes[i].1, amplitudes[i + 1].1))
}
println!("{}", ans.len());
for e in ans {
println!("{} {}", e.0 + 1, e.1 + 1);
}
}
pub mod amplitude {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Amplitude {
pub x: usize,
pub y: usize,
}
impl PartialOrd for Amplitude {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
let sq_dist_1 = self.x.pow(2) + self.y.pow(2);
let sq_dist_2 = other.x.pow(2) + other.y.pow(2);
if self.x == 0 && other.x == 0 {
sq_dist_1.partial_cmp(&sq_dist_2)
} else if self.x == 0 {
Some(std::cmp::Ordering::Greater)
} else if other.x == 0 {
Some(std::cmp::Ordering::Less)
} else {
let frac1 = other.x * self.y;
let frac2 = self.x * other.y;
if frac1 == frac2 {
sq_dist_1.partial_cmp(&sq_dist_2)
} else {
frac1.partial_cmp(&frac2)
}
}
}
}
impl Ord for Amplitude {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.partial_cmp(other).unwrap()
}
}
impl Amplitude {
pub fn new(x: usize, y: usize) -> Self {
Self { x, y }
}
}
}