結果

問題 No.86 TVザッピング(2)
ユーザー yaoshimaxyaoshimax
提出日時 2015-03-01 22:33:48
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 1,163 ms / 5,000 ms
コード長 1,681 bytes
コンパイル時間 2,047 ms
コンパイル使用メモリ 77,364 KB
実行使用メモリ 95,916 KB
最終ジャッジ日時 2023-08-26 15:01:01
合計ジャッジ時間 7,942 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
77,260 KB
testcase_01 AC 72 ms
78,588 KB
testcase_02 AC 68 ms
76,412 KB
testcase_03 AC 67 ms
76,272 KB
testcase_04 AC 69 ms
76,508 KB
testcase_05 AC 70 ms
76,156 KB
testcase_06 AC 67 ms
76,276 KB
testcase_07 AC 67 ms
76,408 KB
testcase_08 AC 75 ms
78,856 KB
testcase_09 AC 1,163 ms
95,428 KB
testcase_10 AC 69 ms
76,400 KB
testcase_11 AC 75 ms
78,788 KB
testcase_12 AC 67 ms
76,704 KB
testcase_13 AC 75 ms
79,216 KB
testcase_14 AC 107 ms
79,448 KB
testcase_15 AC 157 ms
80,592 KB
testcase_16 AC 153 ms
80,376 KB
testcase_17 AC 74 ms
78,892 KB
testcase_18 AC 80 ms
79,064 KB
testcase_19 AC 78 ms
79,004 KB
testcase_20 AC 68 ms
76,280 KB
testcase_21 AC 67 ms
76,352 KB
testcase_22 AC 78 ms
79,116 KB
testcase_23 AC 112 ms
79,444 KB
testcase_24 AC 75 ms
78,840 KB
testcase_25 AC 67 ms
76,308 KB
testcase_26 AC 69 ms
76,320 KB
testcase_27 AC 68 ms
76,260 KB
testcase_28 AC 67 ms
76,396 KB
testcase_29 AC 1,052 ms
95,916 KB
testcase_30 AC 72 ms
76,652 KB
testcase_31 AC 73 ms
78,896 KB
testcase_32 AC 76 ms
79,168 KB
権限があれば一括ダウンロードができます

ソースコード

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