結果

問題 No.707 書道
ユーザー YamaKasaYamaKasa
提出日時 2018-10-01 16:35:56
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,337 bytes
コンパイル時間 1,929 ms
コンパイル使用メモリ 78,680 KB
実行使用メモリ 41,964 KB
最終ジャッジ日時 2024-04-20 14:19:08
合計ジャッジ時間 3,548 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
41,964 KB
testcase_01 AC 112 ms
41,136 KB
testcase_02 AC 103 ms
40,008 KB
testcase_03 AC 103 ms
40,148 KB
testcase_04 AC 96 ms
39,920 KB
testcase_05 WA -
testcase_06 AC 133 ms
41,440 KB
testcase_07 AC 123 ms
40,792 KB
testcase_08 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int H = scan.nextInt();
		int W = scan.nextInt();
		int[][]P = new int[H][W];
		List<Point> list = new ArrayList<Point>();
		for(int i = 0; i < H; i++) {
			String s = scan.next();
			for(int j = 0; j < W; j++) {
				P[i][j] = (int)s.charAt(j) - '0';
				if(P[i][j] == 1) {
					int x = j + 1;
					int y = i + 1;
					Point p = new Point(x, y);
					list.add(p);
				}
			}
		}
		scan.close();

		double l1 = 0;
		double l2 = 0;
		double ans = Double.MAX_VALUE;
		for(int i = 1; i <= W; i++) {
			l1 = 0;
			l2 = 0;
			for(Point p : list) {
				int x = p.x;
				int y = p.y;
				int dx1 = i - x;
				int dy1 = 0 - y;
				l1 += Math.sqrt(dx1 * dx1 + dy1 * dy1);
				int dy2 = H + 1 - y;
				l2 += Math.sqrt(dx1 * dx1 + dy2 * dy2);
			}
			ans = Math.min(l1, l2);
		}
		for(int i = 1; i <= H; i++) {
			l1 = 0;
			l2 = 0;
			for(Point p : list) {
				int x = p.x;
				int y = p.y;
				int dx1 = 0 - x;
				int dy1 = i - y;
				l1 += Math.sqrt(dx1 * dx1 + dy1 * dy1);
				int dx2 = W + 1 - x;
				l2 += Math.sqrt(dx2 * dx2 + dy1 * dy1);
			}
			ans = Math.min(ans, l1);
			ans = Math.min(ans, l2);
		}
		System.out.println(ans);
	}
}
0