結果
問題 | No.707 書道 |
ユーザー | YamaKasa |
提出日時 | 2018-10-01 16:58:40 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 151 ms / 2,000 ms |
コード長 | 1,366 bytes |
コンパイル時間 | 2,138 ms |
コンパイル使用メモリ | 75,344 KB |
実行使用メモリ | 56,236 KB |
最終ジャッジ日時 | 2023-08-02 14:14:19 |
合計ジャッジ時間 | 3,962 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 123 ms
56,140 KB |
testcase_01 | AC | 124 ms
55,920 KB |
testcase_02 | AC | 133 ms
55,908 KB |
testcase_03 | AC | 123 ms
56,236 KB |
testcase_04 | AC | 122 ms
56,028 KB |
testcase_05 | AC | 143 ms
55,916 KB |
testcase_06 | AC | 142 ms
55,800 KB |
testcase_07 | AC | 151 ms
55,596 KB |
testcase_08 | AC | 124 ms
56,076 KB |
ソースコード
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(ans, l1); ans = Math.min(ans, 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); } }