In [2]:
import time
def find_path(n,l,all_path):
start_time = time.time()
result= []
paths = []
go_down = 0
for path in all_path:
floor = path[0]
for i in range(len(path)):
if sum(path)/n == path[0]:
go_down = 0
floor = 0
result.append(True)
paths.append(path)
break
if i == 0:
continue
if i == n-1:
go_down = 0
floor = 0
result.append(True)
paths.append(path)
break
if i != 0:
if path[i] == path[i+1] and path[i-1] == path[i]:
continue
if path[i] == floor:
continue
#내려가기
if path[i] < floor:
if floor-path[i] >= 2:
break
if (i+l-1) > n-1:
break
else:
if sum(path[i:i+l])/ l != path[i]:
break
else:
floor = path[i]
go_down = i
continue
#올라가기
if path[i] > floor:
if path[i] - floor >= 2:
break
if i-l < 0:
break
else:
if go_down > 0:
if i-go_down < l*2:
go_down = 0
break
if go_down == 0:
if sum(path[i-l:i])/l != path[i-l]:
break
else:
floor = path[i]
continue
finish_time = time.time()
print(finish_time - start_time)
return sum(result), paths
n,l = list(map(int,input().split()))
all_path = []
for i in range(n):
path = list(map(int,input().split()))
all_path.append(path)
all_path2 = [list(x) for x in zip(*all_path)]
all_path = all_path + all_path2
print(find_path(n,l,all_path))
In [5]:
n,l = list(map(int,input().split()))
all_path = []
for i in range(n):
path = list(map(int,input().split()))
all_path.append(path)
all_path2 = [list(x) for x in zip(*all_path)]
all_path = all_path + all_path2
print(find_path(n,l,all_path))
In [6]:
n,l = list(map(int,input().split()))
all_path = []
for i in range(n):
path = list(map(int,input().split()))
all_path.append(path)
all_path2 = [list(x) for x in zip(*all_path)]
all_path = all_path + all_path2
print(find_path(n,l,all_path))
In [7]:
n,l = list(map(int,input().split()))
all_path = []
for i in range(n):
path = list(map(int,input().split()))
all_path.append(path)
all_path2 = [list(x) for x in zip(*all_path)]
all_path = all_path + all_path2
print(find_path(n,l,all_path))