結果

問題 No.2456 Stamp Art
ユーザー 👑 rin204rin204
提出日時 2023-09-01 22:08:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,260 ms / 5,000 ms
コード長 1,113 bytes
コンパイル時間 518 ms
コンパイル使用メモリ 86,952 KB
実行使用メモリ 324,432 KB
最終ジャッジ日時 2023-09-02 11:18:07
合計ジャッジ時間 26,551 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
70,936 KB
testcase_01 AC 70 ms
71,324 KB
testcase_02 AC 71 ms
71,132 KB
testcase_03 AC 1,061 ms
319,804 KB
testcase_04 AC 68 ms
71,132 KB
testcase_05 AC 83 ms
75,840 KB
testcase_06 AC 1,260 ms
320,368 KB
testcase_07 AC 1,314 ms
302,116 KB
testcase_08 AC 1,153 ms
321,648 KB
testcase_09 AC 1,365 ms
302,828 KB
testcase_10 AC 2,260 ms
323,588 KB
testcase_11 AC 1,342 ms
319,648 KB
testcase_12 AC 1,497 ms
301,972 KB
testcase_13 AC 1,964 ms
319,836 KB
testcase_14 AC 2,099 ms
318,996 KB
testcase_15 AC 1,054 ms
319,564 KB
testcase_16 AC 835 ms
199,072 KB
testcase_17 AC 91 ms
76,592 KB
testcase_18 AC 74 ms
75,784 KB
testcase_19 AC 808 ms
291,904 KB
testcase_20 AC 1,875 ms
320,692 KB
testcase_21 AC 1,629 ms
319,412 KB
testcase_22 AC 1,751 ms
324,432 KB
testcase_23 AC 167 ms
82,752 KB
testcase_24 AC 275 ms
86,912 KB
testcase_25 AC 71 ms
70,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h, w = map(int, input().split())
S = [input() for _ in range(h)]
cum = [[0] * (w + 1) for _ in range(h + 1)]
for i in range(h):
    for j in range(w):
        if S[i][j] == "#":
            cum[i + 1][j + 1] = 1
        cum[i + 1][j + 1] += cum[i + 1][j] + cum[i][j + 1] - cum[i][j]


def ok(x):
    dp = [[0] * (w + 1) for _ in range(h + 1)]
    for i in range(h - x + 1):
        for j in range(w - x + 1):
            c = cum[i + x][j + x] - cum[i + x][j] - cum[i][j + x] + cum[i][j]
            if c == x * x:
                dp[i][j] += 1
                dp[i + x][j] -= 1
                dp[i][j + x] -= 1
                dp[i + x][j + x] += 1

    for i in range(h):
        for j in range(w - 1):
            dp[i][j + 1] += dp[i][j]

    for i in range(h - 1):
        for j in range(w):
            dp[i + 1][j] += dp[i][j]

    for i in range(h):
        for j in range(w):
            if dp[i][j] == 0 and S[i][j] == "#":
                return False
    return True


l = 1
r = min(h, w) + 1
while r - l > 1:
    mid = (l + r) // 2
    if ok(mid):
        l = mid
    else:
        r = mid

print(l)
0