結果
| 問題 | No.707 書道 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2018-09-17 11:03:48 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 137 ms / 2,000 ms | 
| コード長 | 1,380 bytes | 
| コンパイル時間 | 3,731 ms | 
| コンパイル使用メモリ | 78,888 KB | 
| 実行使用メモリ | 54,244 KB | 
| 最終ジャッジ日時 | 2024-07-18 07:36:08 | 
| 合計ジャッジ時間 | 4,950 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 6 | 
ソースコード
import java.io.*;
import java.util.*;
public class Main_yukicoder707 {
	private static Scanner sc;
	private static Printer pr;
	private static void solve() {
		int h = sc.nextInt();
		int w = sc.nextInt();
		
		char[][] p = new char[h][];
		for (int i = 0; i < h; i++) {
			p[i] = sc.next().toCharArray();
		}
		double min = Double.MAX_VALUE;
		for (int i = 1; i <= h; i++) {
			min = Math.min(min, d(p, i, 0));
			min = Math.min(min, d(p, i, w + 1));
		}
		for (int j = 1; j <= w; j++) {
			min = Math.min(min, d(p, 0, j));
			min = Math.min(min, d(p, h + 1, j));
		}
		
		pr.printf("%.7f\n", min);
	}
	private static double d(char[][] p, int y, int x) {
		int h = p.length;
		int w = p[0].length;
		double d = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (p[i][j] == '1') {
					d += Math.sqrt((i + 1 - y) * (i + 1 - y) + (j + 1 - x) * (j + 1 - x));
				}
			}
		}
//		pr.printf("%d %d %f\n", y, x, d);
		return d;
	}
	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
		pr = new Printer(System.out);
		solve();
//		pr.close();
		pr.flush();
//		sc.close();
	}
	static String INPUT = null;
	private static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}
            
            
            
        