結果

問題 No.157 2つの空洞
ユーザー rocoderrocoder
提出日時 2017-08-07 05:54:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 2,447 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-20 04:09:02
合計ジャッジ時間 1,506 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
11,136 KB
testcase_01 AC 28 ms
11,136 KB
testcase_02 AC 28 ms
11,136 KB
testcase_03 AC 27 ms
11,136 KB
testcase_04 AC 26 ms
11,136 KB
testcase_05 AC 25 ms
11,136 KB
testcase_06 AC 26 ms
11,136 KB
testcase_07 AC 26 ms
11,264 KB
testcase_08 RE -
testcase_09 AC 26 ms
11,136 KB
testcase_10 AC 26 ms
11,136 KB
testcase_11 AC 26 ms
11,136 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 28 ms
11,136 KB
testcase_15 AC 27 ms
11,136 KB
testcase_16 AC 27 ms
11,136 KB
testcase_17 AC 30 ms
11,136 KB
testcase_18 AC 27 ms
11,264 KB
testcase_19 AC 27 ms
11,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# your code goes here
#hole
def ab(a1):
    if a1<0:
        a1*=-1
    return a1
W,H=(int(i) for i in input().split())
C=[input() for i in range(H)]
D=[]
for i in range(H):
    D.append([])
    for j in range(W):
        D[i].append(0)
a=[]
for i in range(H):
    a.append([])
    for j in range(W):
        a[i].append(0)
h=[[],[]]
#print(C)
for l in range(2):
    Nd=0
    i=0
    if l==1:
        i=h[0][0][0]
    while i<H and Nd==0:
        j=0
        if l==1:
            j=h[0][0][1]
        while j<W and Nd==0:
            if C[i][j]=="." and l==0:
                D[i][j]=l+1
                Nd=1
            elif C[i][j]=="." and l==1:
                if D[i][j]!=1:
                    D[i][j]=l+1
                    Nd=1
            j+=1
        i+=1
    i-=1
    j-=1
    h[l].append([i,j])
    v=[[i,j]]
    vn=[[i,j]]
    a[i][j]=1
    while vn!=[]:
        i=0
        v=vn
        vn=[]
        while i<len(v):
            j=-1
            while j<2:
                k=-1
                while k<2:
                    if ab(j)+ab(k)<2:
                        vh=v[i][0]+j
                        vw=v[i][1]+k
                        if a[vh][vw]==0:
                            a[vh][vw]=1
                            if C[vh][vw]==".":
                                D[vh][vw]=l+1
                                vn.append([vh,vw])
                                h[l].append([vh,vw])
                    k+=1
                j+=1
            i+=1
 #   print(D)
#print(D)
for i in range(H):
    for j in range(W):
        if D[i][j]==1:
            a[i][j]=1
        else:
            a[i][j]=0
i=0
Nd=0
vn=h[0]
v=[[0,0]]
#print(a)
while Nd==0 and i<W*H:
    v=vn
    vn=[]
#    print(v)
    j=0
 #   print(len(v))
    while j<len(v):
        k=-1
        while k<2:
            l=-1
            while l<2:
                if ab(l)+ab(k)<2:
            #        print(v[j])
              #      print(i)
             #       print(j)
                    vh=v[j][0]+k
                    vw=v[j][1]+l
                #    print(vh)
                    if vh>=0 and vh<H and vw>=0 and vw<W:
                        if a[vh][vw]==0:
                            a[vh][vw]=1
                            if D[vh][vw]==2:
                                Nd=1
                            elif C[vh][vw]=="#":
                                vn.append([vh,vw])
                l+=1
            k+=1
        j+=1
    i+=1
print(i-1)
0