結果

問題 No.3042 拡大コピー
ユーザー atcoder8
提出日時 2025-02-28 23:16:08
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 870 bytes
コンパイル時間 12,883 ms
コンパイル使用メモリ 399,108 KB
実行使用メモリ 25,968 KB
最終ジャッジ日時 2025-03-01 07:41:55
合計ジャッジ時間 11,972 ms
ジャッジサーバーID
(参考情報)
judge1 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 4 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

use proconio::input;

type Coord = (f64, f64);

fn main() {
    input! {
        n: usize,
        xy: [(f64, f64); n],
        zw: [(f64, f64); n],
    }

    let max_dist_xy = calc_max_dist(&xy);
    let max_dist_zw = calc_max_dist(&zw);

    println!("{}", max_dist_zw / max_dist_xy);
}

fn calc_center(coords: &[Coord]) -> Coord {
    let mut sum_x = 0.0;
    let mut sum_y = 0.0;
    for &(x, y) in coords {
        sum_x += x;
        sum_y += y;
    }

    (sum_x / coords.len() as f64, sum_y / coords.len() as f64)
}

fn calc_dist(coord1: Coord, coord2: Coord) -> f64 {
    (coord1.0 - coord2.0).abs() + (coord1.1 - coord2.1).abs()
}

fn calc_max_dist(coords: &[Coord]) -> f64 {
    let center = calc_center(coords);
    coords
        .iter()
        .map(|&coord| calc_dist(coord, center))
        .max_by(|x, y| x.partial_cmp(y).unwrap())
        .unwrap()
}
0