結果

問題 No.2731 Two Colors
ユーザー 杉浦海翔杉浦海翔
提出日時 2024-05-09 14:05:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,276 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 31,360 KB
最終ジャッジ日時 2024-05-09 14:05:31
合計ジャッジ時間 7,969 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 RE -
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int, input().split())
A = [input() for _ in range(H)]

l = [[0] * W for i in range(H)]

l[0][0]=1
l[H-1][W-1]=1
aa=0
ab=0
ba=H-1
bb=W-1
a=0
b=0
c=1
cnt=2
while (c>=1):
    m=0
    if(a%2==0):
        if(aa>0 and l[aa-1][ab]==0):
            if(m==0 or A[aa-1][ab]<m):
                m=A[aa-1][ab]
                a=aa-1
                b=ab
                
        if(ab>0 and l[aa][ab-1]==0):
            if(m==0 or A[aa][ab-1]<m):
                m=A[aa][ab-1]
                a=aa
                b=ab-1
                
        if(aa<W and l[aa+1][ab]==0):
            if(m==0 or A[aa+1][ab]<m):
                m=A[aa+1][ab]
                a=aa+1
                b=ab
                
        if(ab<H and l[aa][ab+1]==0):
            if(m==0 or A[aa][ab+1]<m):
                m=A[aa][ab+1]
                a=aa
                b=ab+1
        
        l[a][b]=1
        aa=a
        bb=b
        if(a>0):
            if(l[a-1][b]==2):
                break
        if(b>0):
            if(l[a][b-1]==2):
                break
        if(a<H-1):
            if(l[a+1][b]==2):
                berak
        if(b<W-1):
            if(l[a][b+1]==2):
                berak
        cnt+=1    
    else:
        if(ba>0 and l[ba-1][bb]==0):
            if(m==0 or A[ba-1][bb]<m):
                m=A[ba-1][bb]
                a=ba-1
                b=bb
                
        if(bb>0 and l[ba][bb-1]==0):
            if(m==0 or A[ba][bb-1]<m):
                m=A[ba][bb-1]
                a=ba
                b=bb-1
                
        if(bb>W and l[ba+1][bb]==0):
            if(m==0 or A[ba+1][bb]<m):
                m=A[ba+1][bb]
                a=ba+1
                b=bb
        
        if(bb>H and l[ba][bb+1]==0):
            if(m==0 or A[ba][bb+1]<m):
                m=A[ba][bb+1]
                a=ba
                b=bb+1
        
        l[a][b]=2
        aa=a
        bb=b
        
        if(a>0):
            if(l[a-1][b]==1):
                break
        if(b>0):
            if(l[a][b-1]==1):
                break
        if(a<H-1):
            if(l[a+1][b]==1):
                break
        if(b<W-1):
            if(l[a][b+1]==1):
                break
        
        cnt+=1

print(cnt)
    
    
    
    
    
    
    
    
0