結果
問題 | No.402 最も海から遠い場所 |
ユーザー | Grenache |
提出日時 | 2016-07-23 00:12:32 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 666 ms / 3,000 ms |
コード長 | 2,585 bytes |
コンパイル時間 | 3,863 ms |
コンパイル使用メモリ | 79,180 KB |
実行使用メモリ | 151,708 KB |
最終ジャッジ日時 | 2024-04-24 06:49:09 |
合計ジャッジ時間 | 8,862 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
37,780 KB |
testcase_01 | AC | 65 ms
37,644 KB |
testcase_02 | AC | 62 ms
38,084 KB |
testcase_03 | AC | 50 ms
37,532 KB |
testcase_04 | AC | 51 ms
37,688 KB |
testcase_05 | AC | 53 ms
37,720 KB |
testcase_06 | AC | 54 ms
37,568 KB |
testcase_07 | AC | 56 ms
37,248 KB |
testcase_08 | AC | 52 ms
37,712 KB |
testcase_09 | AC | 60 ms
37,268 KB |
testcase_10 | AC | 54 ms
37,568 KB |
testcase_11 | AC | 57 ms
37,700 KB |
testcase_12 | AC | 65 ms
37,760 KB |
testcase_13 | AC | 98 ms
40,188 KB |
testcase_14 | AC | 87 ms
39,828 KB |
testcase_15 | AC | 174 ms
44,268 KB |
testcase_16 | AC | 205 ms
48,992 KB |
testcase_17 | AC | 571 ms
90,428 KB |
testcase_18 | AC | 666 ms
147,400 KB |
testcase_19 | AC | 621 ms
151,708 KB |
testcase_20 | AC | 652 ms
147,408 KB |
testcase_21 | AC | 644 ms
148,272 KB |
ソースコード
import java.io.*; import java.util.*; public class Main_yukicoder402 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); int[] dx = {1, 0, -1, 0}; int[] dy = {0, 1, 0, -1}; int h = sc.nextInt(); int w = sc.nextInt(); char[][] s = new char[h][]; int[][] ss = new int[h][w]; for (int i = 0; i < h; i++) { s[i] = sc.next().toCharArray(); for (int j = 0; j < w; j++) { if (s[i][j] == '#') { ss[i][j] = 1; } } } int[][] sum = new int[h + 1][w + 1]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { sum[i + 1][j + 1] = sum[i + 1][j] + ss[i][j]; } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { sum[i + 1][j + 1] += sum[i][j + 1]; } } int max = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (s[i][j] != '#') { continue; } for (int k = max; k <= Math.min(h, w); k++) { if (i + k + 1 > h || j + k + 1 > w) { break; } int tmp = sum[i + k + 1][j + k + 1] - sum[i + k + 1][j] - sum[i][j + k + 1] + sum[i][j]; if (tmp == (k + 1) * (k + 1)) { max = Math.max(max, k); } else { break; } } } } pr.println((max + 2) / 2); pr.close(); sc.close(); } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator<String> it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { // it = Arrays.asList(br.readLine().split(" ")).iterator(); it = Arrays.asList(br.readLine().split("\\p{javaWhitespace}+")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }