結果
問題 | No.707 書道 |
ユーザー | 37zigen |
提出日時 | 2018-06-29 22:44:12 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 145 ms / 2,000 ms |
コード長 | 1,086 bytes |
コンパイル時間 | 2,415 ms |
コンパイル使用メモリ | 75,740 KB |
実行使用メモリ | 56,424 KB |
最終ジャッジ日時 | 2023-09-13 15:28:49 |
合計ジャッジ時間 | 4,416 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 119 ms
56,424 KB |
testcase_01 | AC | 118 ms
55,832 KB |
testcase_02 | AC | 128 ms
56,388 KB |
testcase_03 | AC | 118 ms
55,748 KB |
testcase_04 | AC | 119 ms
55,812 KB |
testcase_05 | AC | 145 ms
56,016 KB |
testcase_06 | AC | 143 ms
56,344 KB |
testcase_07 | AC | 144 ms
56,172 KB |
testcase_08 | AC | 120 ms
56,192 KB |
ソースコード
import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) throws FileNotFoundException { new Main().run(); } void run() { Scanner sc = new Scanner(System.in); int H = sc.nextInt(); int W = sc.nextInt(); int[][] P = new int[H][W]; for (int i = 0; i < H; ++i) { char[] c = sc.next().toCharArray(); for (int j = 0; j < W; ++j) { P[i][j] = c[j] - '0'; } } double ans = Double.MAX_VALUE / 3; for (int i = 0; i <= H + 1; ++i) { for (int j = 0; j <= W + 1; ++j) { boolean f1 = i == 0 || i == H + 1; boolean f2 = j == 0 || j == W + 1; if (f1 && f2 || !f1 && !f2) continue; double sum = 0; for (int k = 1; k <= H; ++k) { for (int l = 1; l <= W; ++l) { if (P[k - 1][l - 1] == 1) { sum += Math.sqrt((i - k) * (i - k) + (j - l) * (j - l)); } } } ans = Math.min(ans, sum); } } System.out.println(ans); } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }