結果

問題 No.2641 draw X
ユーザー ニックネームニックネーム
提出日時 2024-02-19 22:47:03
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,211 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 82,504 KB
実行使用メモリ 219,684 KB
最終ジャッジ日時 2024-09-29 02:39:09
合計ジャッジ時間 21,718 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34 WA * 5 TLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w = map(int,input().split())
s = [[v=="#" for v in input()] for _ in range(h)]
lurd = [t[:] for t in s]
for i in range(h-1):
    for j in range(w-1):
        lurd[i+1][j+1] += lurd[i][j]
rdlu = [t[:] for t in s]
for i in range(h-1,0,-1):
    for j in range(w-1,0,-1):
        rdlu[i-1][j-1] += rdlu[i][j]
ruld = [t[:] for t in s]
for i in range(h-1):
    for j in range(w-1,0,-1):
        ruld[i+1][j-1] += ruld[i][j]
ldru = [t[:] for t in s]
for i in range(h-1,0,-1):
    for j in range(w-1):
        ldru[i-1][j+1] += ldru[i][j]
p1 = [[0]*(w+1) for _ in range(h+1)]
p2 = [[0]*(w+1) for _ in range(h+1)]
p3 = [[0]*(w+1) for _ in range(h+1)]
p4 = [[0]*(w+1) for _ in range(h+1)]
for i in range(1,h-1):
    for j in range(1,w-1):
        if s[i][j]==0: continue
        ac1 = 0; wa = min(h-i,w-j)
        while wa-ac1>1:
            wj = (ac1+wa)//2
            if lurd[i+wj][j+wj]-lurd[i][j]==wj: ac1 = wj
            else: wa = wj
        ac2 = 0; wa = min(i+1,j+1)
        while wa-ac2>1:
            wj = (ac2+wa)//2
            if rdlu[i-wj][j-wj]-rdlu[i][j]==wj: ac2 = wj
            else: wa = wj
        ac3 = 0; wa = min(h-i,j+1)
        while wa-ac3>1:
            wj = (ac3+wa)//2
            if ruld[i+wj][j-wj]-ruld[i][j]==wj: ac3 = wj
            else: wa = wj
        ac4 = 0; wa = min(i+1,w-j)
        while wa-ac4>1:
            wj = (ac4+wa)//2
            if ldru[i-wj][j+wj]-ldru[i][j]==wj: ac4 = wj
            else: wa = wj
        m = min(ac1,ac2,ac3,ac4)
        if m==0: continue
        p1[i][j] += 1; p1[i+ac1+1][j+ac1+1] -= 1
        p2[i][j] += 1; p2[i-ac2-1][j-ac2-1] -= 1
        p3[i][j] += 1; p3[i+ac3+1][j-ac3-1] -= 1
        p4[i][j] += 1; p4[i-ac4-1][j+ac4+1] -= 1
for i in range(h):
    for j in range(w):
        p1[i+1][j+1] += p1[i][j]
for i in range(h-1,-1,-1):
    for j in range(w-1,-1,-1):
        p2[i-1][j-1] += p2[i][j]
for i in range(h):
    for j in range(w-1,-1,-1):
        p3[i+1][j-1] += p3[i][j]
for i in range(h-1,-1,-1):
    for j in range(w):
        p4[i-1][j+1] += p4[i][j]
t = [[False]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        t[i][j] = p1[i][j]>0 or p2[i][j]>0 or p3[i][j]>0 or p4[i][j]>0
print("Yes" if s==t else "No")
0