結果

問題 No.1265 Balloon Survival
ユーザー phspls
提出日時 2022-11-13 21:07:45
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 160 ms / 2,000 ms
コード長 1,133 bytes
コンパイル時間 15,987 ms
コンパイル使用メモリ 402,716 KB
実行使用メモリ 14,220 KB
最終ジャッジ日時 2024-09-15 02:33:27
合計ジャッジ時間 19,416 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unnecessary parentheses around assigned value
  --> src/main.rs:21:24
   |
21 |             let dist = ((lx-rx)*(lx-rx) + (ly-ry)*(ly-ry));
   |                        ^                                 ^
   |
   = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
   |
21 -             let dist = ((lx-rx)*(lx-rx) + (ly-ry)*(ly-ry));
21 +             let dist = (lx-rx)*(lx-rx) + (ly-ry)*(ly-ry);
   |

ソースコード

diff #

use std::{collections::BinaryHeap, cmp::Reverse};


fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let ballons = (0..n).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp: Vec<isize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
            (temp[0], temp[1])
        })
        .collect::<Vec<_>>();

    let mut pque = BinaryHeap::new();
    for i in 0..n {
        let (lx, ly) = ballons[i];
        for j in i+1..n {
            let (rx, ry) = ballons[j];
            let dist = ((lx-rx)*(lx-rx) + (ly-ry)*(ly-ry));
            pque.push((Reverse(dist), i, j));
        }
    }
    let mut bombed = vec![false; n];
    let mut result = 0usize;
    while let Some((_, i, j)) = pque.pop() {
        if bombed[i] || bombed[j] { continue; }
        if i == 0 {
            bombed[j] = true;
            result += 1;
        } else {
            bombed[i] = true;
            bombed[j] = true;
        }
    }
    println!("{}", result);
}
0