結果
問題 | No.707 書道 |
ユーザー |
![]() |
提出日時 | 2018-06-29 23:22:45 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,440 bytes |
コンパイル時間 | 13,042 ms |
コンパイル使用メモリ | 393,148 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 00:15:48 |
合計ジャッジ時間 | 13,346 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 |
ソースコード
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+1, &paper);if tmp < ans {ans = tmp;}let tmp = calc(h, w, w+1, y0+1, &paper);if tmp < ans {ans = tmp;}}for x0 in 0..w {let tmp = calc(h, w, x0+1, 0, &paper);if tmp < ans {ans = tmp;}let tmp = calc(h, w, x0+1, 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()}