n, m, k = map(int, raw_input().split())
s = max(m,n)
inf = (s*2)**3+s
arr = [[inf for i in range(m+2)] for i in range(n+2)]
def print_arr():
for i in range(1, n+1):
for j in range(1, m+1):
print arr[i][j],
print
def spiral(x, y, d):
if d == 0:
d = 1
else:
d = -1
num = 1
arr[x][y] = num
times = 1
length = 1
t = -1
while times < n * m:
i = 1
while i <= length:
i += 1
num += 1
x += t
if x <= 0 or x >= n + 1 or y <= 0 or y >= m + 1:
continue
if num < arr[x][y]:
arr[x][y] = num
times += 1
t = 0 - t
i = 1
while i <= length:
i += 1
num += 1
y += t*d
if x <= 0 or x >= n + 1 or y <= 0 or y >= m + 1:
continue
if num < arr[x][y]:
arr[x][y] = num
times += 1
length += 1
for i in range(k):
x, y, k = map(int, raw_input().split())
spiral(x, y, k)
print_arr()
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
11368 KB |
Output is correct |
2 |
Correct |
37 ms |
11616 KB |
Output is correct |
3 |
Correct |
32 ms |
11616 KB |
Output is correct |
4 |
Correct |
32 ms |
11616 KB |
Output is correct |
5 |
Correct |
34 ms |
11616 KB |
Output is correct |
6 |
Correct |
68 ms |
13116 KB |
Output is correct |
7 |
Correct |
45 ms |
13116 KB |
Output is correct |
8 |
Correct |
38 ms |
13116 KB |
Output is correct |
9 |
Correct |
547 ms |
15692 KB |
Output is correct |
10 |
Correct |
72 ms |
15692 KB |
Output is correct |