結果
問題 | No.707 書道 |
ユーザー |
![]() |
提出日時 | 2020-03-15 14:50:00 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 174 ms / 2,000 ms |
コード長 | 3,178 bytes |
コンパイル時間 | 2,329 ms |
コンパイル使用メモリ | 81,168 KB |
実行使用メモリ | 54,752 KB |
最終ジャッジ日時 | 2024-11-25 00:23:52 |
合計ジャッジ時間 | 4,350 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 |
ソースコード
import java.io.OutputStream;import java.io.IOException;import java.io.InputStream;import java.io.PrintWriter;import java.util.Arrays;import java.util.Scanner;/*** Built using CHelper plug-in* Actual solution is at the top** @author silviase*/public class Main {public static void main(String[] args) {InputStream inputStream = System.in;OutputStream outputStream = System.out;Scanner in = new Scanner(inputStream);PrintWriter out = new PrintWriter(outputStream);Caligraphy solver = new Caligraphy();solver.solve(1, in, out);out.close();}static class Caligraphy {public void solve(int testNumber, Scanner in, PrintWriter out) {// long でchminint h = in.nextInt();int w = in.nextInt();char[][] c = new char[h + 2][w + 2];Pair p = new Pair(0, 0);for (int i = 1; i <= h; i++) {String s = in.next();Arrays.fill(c[i], '0');for (int j = 0; j < w; j++) {c[i][j + 1] = s.charAt(j);}}double res = 1e11;for (int i = 1; i <= h; i++) {double cmp = 0;for (int j = 1; j <= h; j++) {for (int k = 1; k <= w; k++) {if (c[j][k] == '1') {cmp += Math.sqrt((i - j) * (i - j) + (0 - k) * (0 - k));}}}res = Math.min(res, cmp);cmp = 0;for (int j = 1; j <= h; j++) {for (int k = 1; k <= w; k++) {if (c[j][k] == '1') {cmp += Math.sqrt((i - j) * (i - j) + (w + 1 - k) * (w + 1 - k));}}}res = Math.min(res, cmp);}for (int i = 1; i <= w; i++) {double cmp = 0;for (int j = 1; j <= h; j++) {for (int k = 1; k <= w; k++) {if (c[j][k] == '1') {cmp += Math.sqrt((0 - j) * (0 - j) + (i - k) * (i - k));}}}res = Math.min(res, cmp);cmp = 0;for (int j = 1; j <= h; j++) {for (int k = 1; k <= w; k++) {if (c[j][k] == '1') {cmp += Math.sqrt((h + 1 - j) * (h + 1 - j) + (i - k) * (i - k));}}}res = Math.min(res, cmp);}out.println(res);}}static class Pair {public long x;public long y;public Pair(long x, long y) {this.x = x;this.y = y;}public String toString() {return "Pair{" +"x=" + x +", y=" + y +'}';}}}