結果
| 問題 | No.707 書道 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2018-09-28 21:18:48 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 2,331 bytes | 
| コンパイル時間 | 12,011 ms | 
| コンパイル使用メモリ | 402,512 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-10-12 05:35:41 | 
| 合計ジャッジ時間 | 12,914 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 6 | 
ソースコード
#![allow(non_snake_case)]
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut tokens = $s.split_whitespace();
        input_inner! { tokens, $($r)* }
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut res = String::new();
            ::std::io::stdin().read_to_string(&mut res).unwrap();
            res
        };
        let mut tokens = s.split_whitespace();
        input_inner! { tokens, $($r)* }
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($tokens:expr)  => {};
    ($tokens:expr,) => {};
    ($tokens:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($tokens, $t);
        input_inner! { $tokens $($r)* }
    };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ($tokens:expr, ( $($t:tt),* )) => {
        $(read_value!($tokens, $t)),*
    };
    ($tokens:expr, [ $t:tt; $len:expr ]) => {
        (0..$len).map(|_| read_value!($tokens, $t)).collect::<Vec<_>>()
    };
    ($tokens:expr, chars) => {
        read_value!($tokens, String).chars().collect::<Vec<_>>()
    };
    ($tokens:expr, usize1) => {
        read_value!($tokens, usize) - 1
    };
    ($tokens:expr, $t:ty) => {
        $tokens.next().unwrap().parse::<$t>().expect("parse error")
    };
}
use std::f64;
fn chmin<T>(xmin: &mut T, x: T) -> bool
    where T: PartialOrd + Copy
{
    if x < *xmin {
        *xmin = x;
        true
    }
    else {
        false
    }
}
fn dist(x1: i32, y1: i32, x2: i32, y2: i32) -> f64 {
    let x1 = f64::from(x1);
    let y1 = f64::from(y1);
    let x2 = f64::from(x2);
    let y2 = f64::from(y2);
    let dx = x1 - x2;
    let dy = y1 - y2;
    (dx*dx + dy*dy).sqrt()
}
fn main() {
    input! {
        H: i32,
        W: i32,
        M: [chars; H],
    }
    let it1 = (0..W).map(|x| ( x,-1));
    let it2 = (0..W).map(|x| ( x, H));
    let it3 = (0..H).map(|y| (-1, y));
    let it4 = (0..H).map(|y| ( W, y));
    let it = it1.chain(it2).chain(it3).chain(it4);
    let mut ans = f64::MAX;
    for (px,py) in it {
        let mut cur = 0.0;
        for y in 0..H { for x in 0..W {
            if M[y as usize][x as usize] == '1' {
                cur += dist(px,py,x,y);
            }
        }}
        chmin(&mut ans, cur);
    }
    println!("{}", ans);
}
            
            
            
        