結果
問題 | No.2909 Imaginary Summer |
ユーザー | ArcAki |
提出日時 | 2024-09-24 20:23:00 |
言語 | Rust (1.77.0 + proconio) |
結果 |
RE
|
実行時間 | - |
コード長 | 4,642 bytes |
コンパイル時間 | 14,119 ms |
コンパイル使用メモリ | 388,604 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-02 17:31:09 |
合計ジャッジ時間 | 16,500 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
コンパイルメッセージ
warning: unused variable: `v` --> src/main.rs:130:52 | 130 | n: usize, m: usize, k: usize, p: [i64; 2], v: f64, | ^ | help: `v` is captured in macro and introduced a unused variable --> src/main.rs:31:13 | 31 | let $var = read_value!($next, $t); | ^^^^ ... 129 | / input!{ 130 | | n: usize, m: usize, k: usize, p: [i64; 2], v: f64, 131 | | e: [(usize1, usize1); m], 132 | | s: [[i64; 2]; n], 133 | | t: [[i64; 2]; k], 134 | | } | |_____- in this macro invocation = note: `#[warn(unused_variables)]` on by default = note: this warning originates in the macro `input_inner` which comes from the expansion of the macro `input` (in Nightly builds, run with -Z macro-backtrace for more info) warning: unused variable: `ss` --> src/main.rs:149:9 | 149 | let ss = dic[&(hotel.0[0], hotel.0[1])]; | ^^ help: if this is intentional, prefix it with an underscore: `_ss` warning: variable does not need to be mutable --> src/main.rs:151:9 | 151 | let mut time = vec![0.; n]; | ----^^^^ | | | help: remove this `mut` | = note: `#[warn(unused_mut)]` on by default
ソースコード
#[allow(unused_imports)] use std::{collections::{HashSet, HashMap, BTreeSet, BTreeMap, BinaryHeap, VecDeque}, cmp::{Reverse, max, min}, mem::swap}; // https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8からお借りしました macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($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, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; } #[derive(Debug)] struct KDNode{ point: Vec<i64>, left: Option<usize>, right: Option<usize>, } pub struct KDTree{ tree: Vec<KDNode>, } impl KDTree { pub fn new() -> Self{ KDTree {tree: Vec::new()} } pub fn build(&mut self, points: &mut Vec<Vec<i64>>, d: usize)->Option<usize>{ if points.is_empty(){return None;} let k = points[0].len(); let axis = d%k; let sort = points; sort.sort_by(|a, b| a[axis].cmp(&b[axis])); let m =sort.len()/2; let mp = sort[m].clone(); let ind = self.tree.len(); self.tree.push(KDNode{ point: mp, left: None, right: None }); let left = self.build(&mut sort[..m].to_vec(), d+1); self.tree[ind].left = left; let right = self.build(&mut sort[m+1..].to_vec(), d+1); self.tree[ind].right = right; Some(ind) } pub fn query(&mut self, t: &Vec<i64>, i: Option<usize>, d: usize, res: &mut (Vec<i64>, f64)){ if let Some(idx) = i{ let node = self.tree[idx].point.clone(); let k = t.len(); let axis = d%k; let dist = dist_calc(&node, t); if dist < res.1{ *res = (node.clone(), dist); } let (nex, other) = if t[axis] < node[axis]{ let p = self.tree[idx].left; let q = self.tree[idx].right; (p, q) } else { let p = self.tree[idx].right; let q = self.tree[idx].left; (p, q) }; self.query(t, nex, d+1, res); let di = (node[axis]-t[axis]).abs(); if (di as f64) < res.1{ if let Some(n_idx) = other{ self.query(t, Some(n_idx), d+1, res); } } } } } fn dist_calc(p: &Vec<i64>, q: &Vec<i64>)->f64{ p.iter().zip(q.iter()).map(|(&a, &b)| (a as f64-b as f64)*(a as f64-b as f64)).sum::<f64>().sqrt() } fn main() { input!{ n: usize, m: usize, k: usize, p: [i64; 2], v: f64, e: [(usize1, usize1); m], s: [[i64; 2]; n], t: [[i64; 2]; k], } let mut s = s.clone(); let mut edge = vec![Vec::new(); n]; for &(u, v) in &e{ edge[u].push(v); edge[v].push(u); } let mut dic = HashMap::new(); for i in 0..n{ dic.insert((s[i][0], s[i][1]), i); } let mut kdtree = KDTree::new(); kdtree.build(&mut s, 0); let mut hotel = (Vec::new(), 1e18); kdtree.query(&p, Some(0), 0, &mut hotel); let ss = dic[&(hotel.0[0], hotel.0[1])]; let pre = hotel.1; let mut time = vec![0.; n]; let mut ans = 0.; for i in 0..k{ let mut st = (Vec::new(), 1e18); kdtree.query(&t[i], Some(0), 0, &mut st); let d1 = dist_calc(&st.0, &t[i]); let t1 = time[dic[&(st.0[0], st.0[1])]]; ans += (dist_calc(&p, &t[i]).min(pre+d1+t1))*2.; } println!("{}", ans); }