結果

問題 No.168 ものさし
ユーザー kenkooookenkoooo
提出日時 2015-03-20 00:22:16
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,366 bytes
コンパイル時間 2,162 ms
コンパイル使用メモリ 80,328 KB
実行使用メモリ 77,500 KB
最終ジャッジ日時 2023-09-11 08:56:03
合計ジャッジ時間 15,943 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.math.BigDecimal;
import java.math.MathContext;

public class Main {
	private static int[] x;
	private static int[] y;
	private static final int MAX = 1000000000;

	public static void main(String[] args) {
		int N = nextInt();
		x = new int[N];
		y = new int[N];
		for (int i = 0; i < N; i++) {
			x[i] = nextInt();
			y[i] = nextInt();
		}

		int[][] map = new int[N][N];
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				BigDecimal dist = dist(i, j);
				BigDecimal bd1 = dist.divide(new BigDecimal(10));
				BigDecimal bd5 = bd1.setScale(0, BigDecimal.ROUND_UP);
				int bd2 = bd5.multiply(new BigDecimal(10)).intValue();

				map[i][j] = (int) bd2;
				map[j][i] = (int) bd2;
			}
		}

		for (int i = 0; i < map.length; i++) {
			for (int j = 0; j < map[i].length; j++) {
				System.out.print(map[i][j] + " ");
			}
			System.out.println();
		}
		// ワーシャルフロイト
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (map[i][j] == 0) {
					map[i][j] = MAX;
				}
			}
		}
		for (int k = 0; k < N; k++) {
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					map[i][j] = Math.min(map[i][j], Math.max(map[i][k], map[k][j]));
				}
			}
		}
		// ワーシャルフロイト終わり

		System.out.println(map[0][N - 1]);
	}

	static BigDecimal dist(int i, int j) {
		long xl = x[i] - x[j];
		long yl = y[i] - y[j];
		BigDecimal b1 = new BigDecimal(xl * xl + yl * yl);
		return sqrt(b1, 12);
	}

	static BigDecimal sqrt(BigDecimal a, int scale) {
		// とりあえずdoubleのsqrtを求める
		BigDecimal x = new BigDecimal(Math.sqrt(a.doubleValue()), MathContext.DECIMAL64);

		BigDecimal b2 = new BigDecimal(2);
		for (int tempScale = 8; tempScale < scale; tempScale *= 2) {
			// x = x - (x * x - a) / (2 * x);
			x = x.subtract(x.multiply(x).subtract(a).divide(x.multiply(b2), scale, BigDecimal.ROUND_HALF_EVEN));
		}
		return x;
	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return -1;
	}
}
0