結果

問題 No.707 書道
ユーザー GrenacheGrenache
提出日時 2018-09-17 11:03:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 1,380 bytes
コンパイル時間 3,306 ms
コンパイル使用メモリ 75,708 KB
実行使用メモリ 56,196 KB
最終ジャッジ日時 2023-09-25 09:18:03
合計ジャッジ時間 5,447 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,844 KB
testcase_01 AC 129 ms
55,872 KB
testcase_02 AC 137 ms
56,108 KB
testcase_03 AC 128 ms
55,800 KB
testcase_04 AC 123 ms
55,960 KB
testcase_05 AC 136 ms
56,196 KB
testcase_06 AC 139 ms
55,860 KB
testcase_07 AC 140 ms
55,956 KB
testcase_08 AC 124 ms
56,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
		}
	}
}
0