結果
問題 | No.86 TVザッピング(2) |
ユーザー | titia |
提出日時 | 2022-01-13 03:13:40 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,186 bytes |
コンパイル時間 | 66 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 11,264 KB |
最終ジャッジ日時 | 2024-04-27 17:27:48 |
合計ジャッジ時間 | 9,065 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 25 ms
11,008 KB |
testcase_01 | AC | 25 ms
11,008 KB |
testcase_02 | AC | 26 ms
11,008 KB |
testcase_03 | AC | 28 ms
11,008 KB |
testcase_04 | AC | 28 ms
11,008 KB |
testcase_05 | AC | 28 ms
11,136 KB |
testcase_06 | AC | 26 ms
11,008 KB |
testcase_07 | AC | 28 ms
11,008 KB |
testcase_08 | AC | 27 ms
11,136 KB |
testcase_09 | AC | 1,710 ms
11,008 KB |
testcase_10 | TLE | - |
testcase_11 | AC | 28 ms
11,008 KB |
testcase_12 | AC | 25 ms
11,136 KB |
testcase_13 | AC | 26 ms
11,008 KB |
testcase_14 | AC | 54 ms
11,136 KB |
testcase_15 | AC | 113 ms
11,136 KB |
testcase_16 | AC | 137 ms
11,136 KB |
testcase_17 | AC | 30 ms
11,136 KB |
testcase_18 | AC | 29 ms
11,136 KB |
testcase_19 | AC | 28 ms
11,264 KB |
testcase_20 | AC | 29 ms
11,008 KB |
testcase_21 | TLE | - |
testcase_22 | AC | 28 ms
11,136 KB |
testcase_23 | AC | 60 ms
11,136 KB |
testcase_24 | AC | 29 ms
11,008 KB |
testcase_25 | AC | 26 ms
11,136 KB |
testcase_26 | AC | 25 ms
11,008 KB |
testcase_27 | AC | 26 ms
11,136 KB |
testcase_28 | AC | 25 ms
11,136 KB |
testcase_29 | AC | 711 ms
11,136 KB |
testcase_30 | AC | 27 ms
11,136 KB |
testcase_31 | AC | 27 ms
11,008 KB |
testcase_32 | AC | 27 ms
11,008 KB |
ソースコード
N,M=map(int,input().split()) MAP=[input() for i in range(N)] def findmap(x0,y0,di): USE=[[0]*M for i in range(N)] Q=[(x0,y0,di)] while Q: x,y,di=Q.pop() if USE[x][y]==1: if x==x0 and y==y0: break else: return False USE[x][y]=1 if di=="R": if 0<=x<N and 0<=y+1<M and MAP[x][y+1]==".": Q.append((x,y+1,"R")) elif 0<=x-1<N and 0<=y<M and MAP[x-1][y]==".": Q.append((x-1,y,"U")) else: return False elif di=="L": if 0<=x<N and 0<=y-1<M and MAP[x][y-1]==".": Q.append((x,y-1,"L")) elif 0<=x+1<N and 0<=y<M and MAP[x+1][y]==".": Q.append((x+1,y,"D")) else: return False elif di=="U": if 0<=x-1<N and 0<=y<M and MAP[x-1][y]==".": Q.append((x-1,y,"U")) elif 0<=x<N and 0<=y-1<M and MAP[x][y-1]==".": Q.append((x,y-1,"L")) else: return False elif di=="D": if 0<=x+1<N and 0<=y<M and MAP[x+1][y]==".": Q.append((x+1,y,"D")) elif 0<=x<N and 0<=y+1<M and MAP[x][y+1]==".": Q.append((x,y+1,"R")) else: return False for i in range(N): for j in range(M): if MAP[i][j]=="." and USE[i][j]==0: return False return True for x in range(N): for y in range(M): if 0<=x+1<N and 0<=y<M and MAP[x+1][y]==".": if findmap(x,y,"D")==True: print("YES") exit() if 0<=x-1<N and 0<=y<M and MAP[x-1][y]==".": if findmap(x,y,"U")==True: print("YES") exit() if 0<=x<N and 0<=y+1<M and MAP[x][y+1]==".": if findmap(x,y,"R")==True: print("YES") exit() if 0<=x<N and 0<=y-1<M and MAP[x][y-1]==".": if findmap(x,y,"L")==True: print("YES") exit() else: print("NO")