結果

問題 No.2456 Stamp Art
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2023-09-01 23:06:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 984 ms / 5,000 ms
コード長 1,531 bytes
コンパイル時間 2,219 ms
コンパイル使用メモリ 201,524 KB
実行使用メモリ 87,048 KB
最終ジャッジ日時 2023-09-02 11:20:00
合計ジャッジ時間 18,627 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,592 KB
testcase_01 AC 2 ms
7,452 KB
testcase_02 AC 2 ms
7,516 KB
testcase_03 AC 962 ms
86,844 KB
testcase_04 AC 2 ms
7,512 KB
testcase_05 AC 3 ms
7,408 KB
testcase_06 AC 966 ms
87,048 KB
testcase_07 AC 959 ms
86,888 KB
testcase_08 AC 895 ms
86,772 KB
testcase_09 AC 966 ms
86,768 KB
testcase_10 AC 984 ms
86,712 KB
testcase_11 AC 966 ms
86,772 KB
testcase_12 AC 922 ms
86,704 KB
testcase_13 AC 983 ms
86,576 KB
testcase_14 AC 981 ms
86,944 KB
testcase_15 AC 963 ms
86,668 KB
testcase_16 AC 459 ms
71,628 KB
testcase_17 AC 2 ms
7,456 KB
testcase_18 AC 2 ms
7,336 KB
testcase_19 AC 393 ms
63,436 KB
testcase_20 AC 933 ms
86,872 KB
testcase_21 AC 883 ms
83,752 KB
testcase_22 AC 980 ms
86,484 KB
testcase_23 AC 45 ms
57,420 KB
testcase_24 AC 43 ms
33,600 KB
testcase_25 AC 2 ms
7,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main () {
	int H, W;
	cin >> H >> W;
	int A[4040][4040];
	char C[2020][2020];
	for (int i = 0; i < H; i ++) {
		for (int j = 0; j < W; j ++) {
			char c;
			cin >> c;
			A[i + 1][j + 1] = c == '#';
			C[i][j] = c;
		}
	}
	int ng = min(H, W) + 1, ok = 1;
	for (int i = 0; i <= H + ng; i ++) {
		for (int j = 0; j <= W + ng; j ++) {
			if (0 < i && i <= H && 0 < j && j <= W) continue;
			A[i][j] = 0;
		}
	}
	for (int i = 0; i < H + ng; i ++) {
		for (int j = 1; j < W + ng; j ++) {
			A[i][j] += A[i][j - 1];
		}
	}
	for (int j = 0; j < W + ng; j ++) {
		for (int i = 1; i < H + ng; i ++) {
			A[i][j] += A[i - 1][j];
		}
	}
	int B[2040][2040];
	while (abs(ok - ng) > 1) {
		int mu = (ok + ng) / 2;
		for (int i = 0; i < H; i ++) {
			for (int j = 0; j < W; j ++) {
				B[i][j] = 0;
			}
		}
		for (int i = 0; i < H; i ++) {
			for (int j = 0; j < W; j ++) {
				if (A[i][j] + A[i + mu][j + mu] - A[i][j + mu] - A[i + mu][j] >= mu * mu) {
					B[i][j] ++;
					B[i + mu][j] --;
					B[i][j + mu] --;
					B[i + mu][j + mu] ++;
				}
			}
		}
		for (int i = 0; i < H; i ++) {
			for (int j = 1; j < W; j ++) {
				B[i][j] += B[i][j - 1];
			}
		}
		for (int j = 0; j < W; j ++) {
			for (int i = 1; i < H; i ++) {
				B[i][j] += B[i - 1][j];
			}
		}
		bool cn = true;
		for (int i = 0; i < H; i ++) {
			for (int j = 0; j < W; j ++) {
				if (C[i][j] == '#') {
					cn = cn && B[i][j] > 0;
				}
			}
		}
		if (cn) {
			ok = mu;
		} else {
			ng = mu;
		}
	}
	cout << ok << endl;
}
0