結果

問題 No.2456 Stamp Art
ユーザー ゼットゼット
提出日時 2023-09-02 00:06:39
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,817 bytes
コンパイル時間 743 ms
コンパイル使用メモリ 87,260 KB
実行使用メモリ 114,632 KB
最終ジャッジ日時 2023-09-02 00:06:54
合計ジャッジ時間 12,102 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,416 KB
testcase_01 AC 68 ms
71,452 KB
testcase_02 AC 71 ms
71,076 KB
testcase_03 AC 702 ms
113,612 KB
testcase_04 AC 69 ms
71,500 KB
testcase_05 AC 76 ms
76,160 KB
testcase_06 AC 710 ms
114,572 KB
testcase_07 AC 376 ms
114,232 KB
testcase_08 AC 134 ms
108,020 KB
testcase_09 AC 703 ms
114,632 KB
testcase_10 AC 709 ms
113,584 KB
testcase_11 AC 724 ms
114,344 KB
testcase_12 AC 153 ms
108,336 KB
testcase_13 WA -
testcase_14 AC 727 ms
114,124 KB
testcase_15 AC 667 ms
113,872 KB
testcase_16 AC 426 ms
96,312 KB
testcase_17 AC 113 ms
77,324 KB
testcase_18 AC 69 ms
71,592 KB
testcase_19 AC 534 ms
101,708 KB
testcase_20 AC 264 ms
108,332 KB
testcase_21 AC 589 ms
110,888 KB
testcase_22 AC 622 ms
113,416 KB
testcase_23 AC 154 ms
80,220 KB
testcase_24 AC 189 ms
80,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W=map(int,input().split())
S=[input() for i in range(H)]
v=[[0]*W for i in range(H)]
for i in range(H):
  for j in range(W):
    if S[i][j]=='#':
      v[i][j]+=1
      t=0
      x1,x2=i+1,i-1
      if x1>=H:
        t+=1
      else:
        if S[x1][j]=='.':
          t+=1
      if x2<0:
        t+=1
      else:
        if S[x2][j]=='.':
          t+=1
      if t==2:
        print(1)
        exit()
      t=0
      y1,y2=j+1,j-1
      if y1>=W:
        t+=1
      else:
        if S[i][y1]=='.':
          t+=1
      if y2<0:
        t+=1
      else:
        if S[i][y2]=='.':
          t+=1
        if t==2:
          print(1)
          exit()
for i in range(H):
  for j in range(1,W):
    v[i][j]=v[i][j-1]+v[i][j]
for i in range(1,H):
  for j in range(W):
    v[i][j]=v[i-1][j]+v[i][j]
result=10**10
DX=[1,1,-1,-1]
DY=[1,-1,1,-1]
for i in range(H):
  for j in range(W):
    if S[i][j]=='.':
      continue
    for dx,dy in zip(DX,DY):
      x=i-dx
      y=j-dy
      t=0
      if x<0 or x>=H:
        t+=1
      else:
        if S[x][j]=='.':
          t+=1
      if y<0 or y>=W:
        t+=1
      else:
        if S[i][y]=='.':
          t+=1
      if t==2:
        l=1
        r=2000
        while True:
          m=(l+r+1)//2
          i2,j2=i+dx*(m-1),j+dy*(m-1)
          if i2<0 or i2>=H or j2<0 or j2>=W:
            r=m-1
          else:
            j3=max(j,j2)
            j4=min(j,j2)
            i3=max(i,i2)
            i4=min(i,i2)
            ans=v[i3][j3]
            if j4>0:
              ans-=v[i3][j4-1]
            if i4>0:
              ans-=v[i4-1][j3]
            if i4>0 and j4>0:
              ans+=v[i4-1][j4-1]
            if ans==m**2:
              l=m
            else:
              r=m-1
          if l==r:
            break
        result=min(result,l)
print(result)
      
0