結果

問題 No.402 最も海から遠い場所
ユーザー Grenache
提出日時 2016-07-23 00:12:32
言語 Java
(openjdk 23)
結果
AC  
実行時間 733 ms / 3,000 ms
コード長 2,585 bytes
コンパイル時間 3,925 ms
コンパイル使用メモリ 79,288 KB
実行使用メモリ 164,464 KB
最終ジャッジ日時 2024-11-06 13:57:54
合計ジャッジ時間 10,396 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
		}
	}
}
0