結果

問題 No.86 TVザッピング(2)
ユーザー yaoshimaxyaoshimax
提出日時 2015-03-01 22:33:20
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 1,681 bytes
コンパイル時間 63 ms
コンパイル使用メモリ 6,544 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-06 05:59:51
合計ジャッジ時間 7,140 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,888 KB
testcase_01 AC 11 ms
5,872 KB
testcase_02 AC 10 ms
5,812 KB
testcase_03 AC 10 ms
5,988 KB
testcase_04 AC 9 ms
5,872 KB
testcase_05 AC 8 ms
5,892 KB
testcase_06 AC 9 ms
5,940 KB
testcase_07 AC 9 ms
5,892 KB
testcase_08 AC 16 ms
5,980 KB
testcase_09 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,raw_input().split())
A=[raw_input() for i in range(N)]
dir=[(1,0),(0,1),(-1,0),(0,-1)]
sur=[(-1,-1),(1,1),(1,-1),(-1,1),(1,0),(0,1),(-1,0),(0,-1)]
cnt=0 
for i in range(N):
    for j in range(M):
        if A[i][j]=='.':
            cnt+=1
        if i>0 and i+1<N and j>0 and j+1<M:
            ng=True
            for (a,b) in sur:
                if A[i+a][j+b]!='.':
                    ng=False
                    break
            if ng:
                print "NO"
                exit()
for i in range(N):
    for j in range(M):
        if A[i][j] =='.':
            for k in range(len(dir)):
                arrived=[[False for m in range(M)]for n in range(N)]
                a,b=i,j
                curCnt = 0
                arrived[a][b]=True
                #print (a,b),
                for d in range(6):
                    na,nb=a+dir[(k+d)%4][0],b+dir[(k+d)%4][1]
                    ok = False
                    while na<N and na >=0 and nb <M and nb>=0 and A[na][nb]=='.' and (arrived[na][nb]==False or (i== na and j==nb)):
                            curCnt+=1
                            #print (na,nb) ,
                            arrived[na][nb]=True
                            a=na
                            b=nb
                            ok=True
                            if a==i and b==j:
                                break
                            na,nb=a+dir[(k+d)%4][0],b+dir[(k+d)%4][1]
                    if ok == False or (a==i and b==j ):
                        break
                #print 
                if a==i and b==j and cnt == curCnt:
                    print "YES"
                    exit()
print "NO"


0