結果
問題 | No.2456 Stamp Art |
ユーザー |
![]() |
提出日時 | 2023-09-09 10:16:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 3,820 ms / 5,000 ms |
コード長 | 3,612 bytes |
コンパイル時間 | 179 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 297,696 KB |
最終ジャッジ日時 | 2024-06-27 03:26:26 |
合計ジャッジ時間 | 51,271 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
import sys# sys.setrecursionlimit(200005)# sys.set_int_max_str_digits(1000005)int1 = lambda x: int(x)-1pDB = lambda *x: print(*x, end="\n", file=sys.stderr)p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)def II(): return int(sys.stdin.readline())def LI(): return list(map(int, sys.stdin.readline().split()))def LLI(rows_number): return [LI() for _ in range(rows_number)]def LI1(): return list(map(int1, sys.stdin.readline().split()))def LLI1(rows_number): return [LI1() for _ in range(rows_number)]def SI(): return sys.stdin.readline().rstrip()dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]inf = -1-(-1 << 63)# md = 10**9+7md = 998244353class CumSum2D:def __init__(self, arr, w=None):if w:self.h = arrself.w = welse:self.h = len(arr)self.w = len(arr[0])self.t = [0]*(self.h+1)*(self.w+1)if w == None:w = self.w+1for i, row in enumerate(arr):self.t[(i+1)*w+1:(i+1)*w+w] = rowself._finalized = Falsedef add(self, i, j, c):w = self.w+1self.t[(i+1)*w+j+1] += cdef finalize(self):w = self.w+1self._finalized = Truefor ij in range(w+1, (self.h+1)*w):i, j = divmod(ij, w)if j == 0: continueif j+1 < w: self.t[i*w+j+1] += self.t[i*w+j]self.t[i*w+j] += self.t[(i-1)*w+j]def sum(self, ij0, ij1=None):if not self._finalized:print("Finalize!!!")exit()w = self.w+1i, j = ij0x, y = self.h, self.wif ij1: x, y = ij1if i >= x or j >= y: return 0return self.t[i*w+j]+self.t[x*w+y]-self.t[i*w+y]-self.t[x*w+j]class Imos2D:def __init__(self, arr, w=None):if w:self.h = arrself.w = welse:self.h = len(arr)self.w = len(arr[0])self.t = [0]*(self.h+1)*(self.w+1)if w == None:w = self.w+1for i, row in enumerate(arr):self.t[i*w:i*w+w-1] = rowself._finalized = Falsedef add(self, ij0, ij1, c):i, j = ij0x, y = ij1w = self.w+1self.t[i*w+j] += cself.t[x*w+y] += cself.t[i*w+y] -= cself.t[x*w+j] -= cdef finalize(self):w = self.w+1self._finalized = Truefor ij in range(self.h*w):i, j = divmod(ij, w)if j == w-1: continueself.t[i*w+j+1] += self.t[i*w+j]if i: self.t[i*w+j] += self.t[(i-1)*w+j]def val(self, i, j):if not self._finalized:print("Finalize!!!")exit()return self.t[i*(self.w+1)+j]def binary_search(l, r, minimize):if minimize: l -= 1else: r += 1while l+1 < r:m = (l+r)//2if ok(m) ^ minimize: l = melse: r = mif minimize: return rreturn ldef ok(m):m2 = m**2cur = Imos2D(h, w)for i in range(h-m+1):for j in range(w-m+1):if cs.sum([i, j], [i+m, j+m]) == m2:cur.add([i, j], [i+m, j+m], 1)cur.finalize()for i in range(h):for j in range(w):if (cur.val(i, j) > 0) != (ss[i][j] > 0): return Falsereturn Trueh, w = LI()ss = [[(c == "#")*1 for c in SI()] for _ in range(h)]cs = CumSum2D(ss)cs.finalize()tt = []for s in ss: tt += s+[0]print(binary_search(1, min(h, w), False))