結果

問題 No.402 最も海から遠い場所
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2022-03-07 01:40:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,681 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 10,980 KB
実行使用メモリ 23,876 KB
最終ジャッジ日時 2023-09-28 18:35:55
合計ジャッジ時間 6,793 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
12,540 KB
testcase_01 AC 17 ms
8,048 KB
testcase_02 AC 18 ms
8,112 KB
testcase_03 AC 16 ms
8,024 KB
testcase_04 AC 16 ms
8,252 KB
testcase_05 AC 16 ms
8,072 KB
testcase_06 AC 16 ms
8,120 KB
testcase_07 AC 16 ms
8,212 KB
testcase_08 AC 16 ms
8,172 KB
testcase_09 AC 16 ms
8,068 KB
testcase_10 AC 16 ms
8,112 KB
testcase_11 AC 17 ms
8,128 KB
testcase_12 AC 16 ms
8,104 KB
testcase_13 AC 54 ms
10,392 KB
testcase_14 AC 34 ms
8,760 KB
testcase_15 AC 268 ms
19,232 KB
testcase_16 AC 544 ms
23,876 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.readline
    class cs_2d():
        
        def __init__(self,x):
            
                n = len(x)
                m = len(x[0])
                tmp = [[0]*(m+1) for _ in range(n+1)]
                for i in range(n):
                    tmp[i+1][1:] = x[i]
                    for j in range(m):
                        tmp[i+1][j+1] += tmp[i+1][j]
                
                for j in range(m):
                    for i in range(n):
                        tmp[i+1][j+1] += tmp[i][j+1]
                        
                self.S = tmp
        
        def query(self,ix,jx,iy,jy):
            ##[ix,jx)×[iy,jy)
            
            T = self.S
            
            return T[jx][jy] - T[jx][iy] - T[ix][jy] + T[ix][iy]
            
            
    H,W = map(int,input().split())
    S = [list(map(lambda x : x == '.',input()))[:-1] for _ in range(H)]
    
    C = cs_2d(S)
    
    def is_ok(x,y,n):
        return C.query(x-n+1,x+n,y-n+1,y+n)==0
        
    ans = 1
    for i in range(1,H-1):
        for j in range(ans,W-ans):
            if S[i][j] == 1:
                continue
            L = min(i+1,j+1,H-i,W-j)
            if L <ans+1:
                continue
            if is_ok(i,j,L):
                ans = max(ans,L)
                continue
            
            if not is_ok(i,j,ans+1):
                continue
            y = L
            x = ans+1
            while y-x>1:
                mid = (y+x)//2
                if is_ok(i,j,mid):
                    x = mid
                else:
                    y = mid
            ans = max(ans,x)
    
    print(ans)
main()
    
0