Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pprint import pprint as print
- '''
- 1 1 1 0 0 1 0
- 1 0 1 0 0 1 0
- 1 0 1 1 1 1 0
- 0 1 0 0 1 0 0
- 0 1 0 0 1 1 0
- 0 1 1 1 0 0 0
- счет с единицы, первая коорд-а - y
- '''
- field = list()
- height, width = map(int, input().split())
- for _ in range(height):
- field.append(list(input()))
- res = ""
- for _ in range(int(input())):
- temp = list(map(int, input().split()))
- start, end = temp[:2], temp[2:]
- if start == end:
- res += "1"
- continue
- if field[start[1] - 1][start[0] - 1] == "0":
- res += "0"
- continue
- c = start[1]
- curves = 0
- r = start[0]
- down = False
- while True:
- if curves == 3:
- res += "0"
- break
- if [c, r] == end:
- res += "1"
- break
- try:
- curcell = field[c - 1][r - 1]
- except:
- res += "0"
- break
- if curcell == "1":
- r += 1
- else:
- r -= 1
- c += 1
- curves += 1
- print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement