結果

問題 No.707 書道
ユーザー TheRustWizardOfTheCenturyTheRustWizardOfTheCentury
提出日時 2018-06-29 23:21:18
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,432 bytes
コンパイル時間 566 ms
コンパイル使用メモリ 139,220 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 15:39:54
合計ジャッジ時間 1,243 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::{Read, stdin};

fn main() {
    let mut buf = String::new();
    stdin().read_to_string(&mut buf).unwrap();
    let mut tok = buf.split_whitespace();
    let mut get = || tok.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let h = get!();
    let w = get!();
    
    let mut paper = vec![];
    
    for _ in 0..h {
        paper.push(get().as_bytes());
    }
    
    let mut ans = std::f64::MAX;
    
    for y0 in 0..h {
        let tmp = calc(h, w, 0, y0, &paper);
        if tmp < ans {
            ans = tmp;
        }
        let tmp = calc(h, w, w+1, y0, &paper);
        if tmp < ans {
            ans = tmp;
        }
    }
    for x0 in 0..w {
        let tmp = calc(h, w, x0, 0, &paper);
        if tmp < ans {
            ans = tmp;
        }
        let tmp = calc(h, w, x0, h+1, &paper);
        if tmp < ans {
            ans = tmp;
        }
    }
    
    println!("{}", ans);
}

fn calc(h: i64, w: i64, x0: i64, y0: i64, paper: &Vec<&[u8]>) -> f64 {
    let mut ret = 0.0;
    for y1 in 0..h {
        for x1 in 0..w {
            if paper[y1 as usize][x1 as usize] == b'1' {
                ret += dist(x0, y0, x1+1, y1+1);
            }
        }
    }
    ret
}

fn dist(x0: i64, y0: i64, x1: i64, y1: i64) -> f64 {
    let dx = (x1 - x0) as f64;
    let dy = (y1 - y0) as f64;
    (dx * dx + dy * dy).sqrt()
}
0