結果
問題 | 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 |
コンパイル時間 | 212 ms |
コンパイル使用メモリ | 11,224 KB |
実行使用メモリ | 8,540 KB |
最終ジャッジ日時 | 2023-08-09 23:14:58 |
合計ジャッジ時間 | 16,177 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 18 ms
8,500 KB |
testcase_01 | AC | 18 ms
8,156 KB |
testcase_02 | AC | 17 ms
8,016 KB |
testcase_03 | AC | 17 ms
8,448 KB |
testcase_04 | AC | 16 ms
8,016 KB |
testcase_05 | AC | 17 ms
8,456 KB |
testcase_06 | AC | 16 ms
8,344 KB |
testcase_07 | AC | 16 ms
8,000 KB |
testcase_08 | AC | 17 ms
8,540 KB |
testcase_09 | AC | 1,817 ms
8,076 KB |
testcase_10 | TLE | - |
testcase_11 | AC | 17 ms
8,172 KB |
testcase_12 | AC | 17 ms
8,000 KB |
testcase_13 | AC | 17 ms
7,932 KB |
testcase_14 | AC | 48 ms
8,396 KB |
testcase_15 | AC | 115 ms
8,040 KB |
testcase_16 | AC | 132 ms
8,072 KB |
testcase_17 | AC | 17 ms
8,376 KB |
testcase_18 | AC | 20 ms
8,072 KB |
testcase_19 | AC | 18 ms
8,016 KB |
testcase_20 | AC | 17 ms
8,128 KB |
testcase_21 | AC | 4,805 ms
8,224 KB |
testcase_22 | AC | 17 ms
8,064 KB |
testcase_23 | AC | 54 ms
8,400 KB |
testcase_24 | AC | 18 ms
8,000 KB |
testcase_25 | AC | 18 ms
8,044 KB |
testcase_26 | AC | 17 ms
8,108 KB |
testcase_27 | AC | 17 ms
8,492 KB |
testcase_28 | AC | 16 ms
8,004 KB |
testcase_29 | AC | 908 ms
8,076 KB |
testcase_30 | AC | 16 ms
7,996 KB |
testcase_31 | AC | 17 ms
8,448 KB |
testcase_32 | AC | 17 ms
8,172 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")