結果

問題 No.1265 Balloon Survival
ユーザー phsplsphspls
提出日時 2022-11-13 21:07:45
言語 Rust
(1.77.0)
結果
AC  
実行時間 200 ms / 2,000 ms
コード長 1,133 bytes
コンパイル時間 1,783 ms
コンパイル使用メモリ 152,664 KB
実行使用メモリ 14,224 KB
最終ジャッジ日時 2023-10-13 05:05:03
合計ジャッジ時間 5,635 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,356 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,372 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 10 ms
4,348 KB
testcase_15 AC 7 ms
4,348 KB
testcase_16 AC 3 ms
4,352 KB
testcase_17 AC 67 ms
8,228 KB
testcase_18 AC 4 ms
4,352 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 10 ms
4,348 KB
testcase_21 AC 26 ms
4,888 KB
testcase_22 AC 14 ms
4,348 KB
testcase_23 AC 16 ms
4,352 KB
testcase_24 AC 174 ms
13,704 KB
testcase_25 AC 176 ms
13,680 KB
testcase_26 AC 181 ms
13,704 KB
testcase_27 AC 199 ms
13,644 KB
testcase_28 AC 193 ms
14,224 KB
testcase_29 AC 184 ms
13,672 KB
testcase_30 AC 200 ms
13,632 KB
testcase_31 AC 196 ms
13,704 KB
testcase_32 AC 176 ms
13,676 KB
testcase_33 AC 179 ms
13,676 KB
testcase_34 AC 1 ms
4,348 KB
testcase_35 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unnecessary parentheses around assigned value
  --> 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);
   |

warning: 1 warning emitted

ソースコード

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