結果
問題 | No.2652 [Cherry 6th Tune N] Δρονε χιρχλινγ |
ユーザー | naut3 |
提出日時 | 2024-02-23 23:07:47 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,210 bytes |
コンパイル時間 | 15,304 ms |
コンパイル使用メモリ | 378,312 KB |
実行使用メモリ | 21,248 KB |
最終ジャッジ日時 | 2024-09-29 08:33:21 |
合計ジャッジ時間 | 46,921 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 190 ms
5,248 KB |
testcase_02 | AC | 190 ms
5,248 KB |
testcase_03 | AC | 196 ms
5,248 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | AC | 254 ms
21,248 KB |
testcase_41 | AC | 253 ms
21,120 KB |
コンパイルメッセージ
warning: unused variable: `L` --> src/main.rs:37:9 | 37 | let L = input!(usize); | ^ help: if this is intentional, prefix it with an underscore: `_L` | = note: `#[warn(unused_variables)]` on by default
ソースコード
#![allow(non_snake_case, unused_imports, unused_must_use)] use std::io::{self, prelude::*, BufWriter, StdinLock, StdoutLock}; use std::str; fn main() { let (stdin, stdout) = (io::stdin(), io::stdout()); let mut scan = Scanner::new(stdin.lock()); let mut out = io::BufWriter::new(stdout.lock()); macro_rules! input { ($T: ty) => { scan.token::<$T>() }; ($T: ty, $N: expr) => { (0..$N).map(|_| scan.token::<$T>()).collect::<Vec<_>>() }; } let t = input!(usize); for _ in 0..t { solve(&mut scan, &mut out); } } fn solve(scan: &mut Scanner<StdinLock>, out: &mut BufWriter<StdoutLock>) { macro_rules! input { ($T: ty) => { scan.token::<$T>() }; ($T: ty, $N: expr) => { (0..$N).map(|_| scan.token::<$T>()).collect::<Vec<_>>() }; } let N = input!(usize); let L = input!(usize); let mut P = vec![]; let mut Sxy = std::collections::BTreeSet::new(); let mut Syx = std::collections::BTreeSet::new(); let dist = |p1: (isize, isize), p2: (isize, isize)| return (p1.0 - p2.0).abs() + (p1.1 - p2.1).abs(); for _ in 0..N { let (x, y) = (input!(isize), input!(isize)); P.push((x, y)); Sxy.insert((x, y)); Syx.insert((y, x)); } let (x, y) = P[0]; Sxy.remove(&(x, y)); Syx.remove(&(y, x)); let mut route = vec![P[0]]; let mut now = P[0]; while !Sxy.is_empty() { let mut cand = vec![]; let nxt = Sxy.range(..now).next_back(); if let Some(&p) = nxt { cand.push(p); } let nxt = Sxy.range(now..).next(); if let Some(&p) = nxt { cand.push(p); } let now_inv = (now.1, now.0); let nxt = Syx.range(..now_inv).next_back(); if let Some(&p) = nxt { cand.push((p.1, p.0)); } let nxt = Syx.range(now_inv..).next(); if let Some(&p) = nxt { cand.push((p.1, p.0)); } cand.sort_by_key(|&p| dist(p, now)); let nxt = cand[0]; route.push(nxt); now = nxt; Sxy.remove(&now); Syx.remove(&(now.1, now.0)); } writeln!(out, "{}", route.len()); for (x, y) in route { writeln!(out, "{} {}", x, y); } } struct Scanner<R> { reader: R, buf_str: Vec<u8>, buf_iter: str::SplitWhitespace<'static>, } impl<R: BufRead> Scanner<R> { fn new(reader: R) -> Self { Self { reader, buf_str: vec![], buf_iter: "".split_whitespace(), } } fn token<T: str::FromStr>(&mut self) -> T { loop { if let Some(token) = self.buf_iter.next() { return token.parse().ok().expect("Failed parse"); } self.buf_str.clear(); self.reader .read_until(b'\n', &mut self.buf_str) .expect("Failed read"); self.buf_iter = unsafe { let slice = str::from_utf8_unchecked(&self.buf_str); std::mem::transmute(slice.split_whitespace()) } } } }