-
Notifications
You must be signed in to change notification settings - Fork 0
/
D.py
61 lines (55 loc) · 1.24 KB
/
D.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
field = [[0]*w for _ in range(h)]
def check(field):
for l in field:
print(' '.join(map(str, l)))
rw = w
dh = h
k = 0
count = 0
k_count = 0
while True:
for wi in range(w-rw, rw):
field[h-dh][wi] = k+1
count += 1
k_count += 1
if count >= h*w:
check(field)
exit()
if k_count >= a[k]:
k_count = 0
k += 1
for hi in range(h-dh+1, dh):
field[hi][rw-1] = k+1
count += 1
k_count += 1
if count >= h*w:
check(field)
exit()
if k_count >= a[k]:
k_count = 0
k += 1
for wi in range(1, 2*rw - w):
field[dh-1][rw-wi-1] = k+1
count += 1
k_count += 1
if count >= h*w:
check(field)
exit()
if k_count >= a[k]:
k_count = 0
k += 1
for hi in range(1, 2*dh - h -1):
field[dh-hi-1][w-rw] = k+1
count += 1
k_count += 1
if count >= h*w:
check(field)
exit()
if k_count >= a[k]:
k_count = 0
k += 1
rw -= 1
dh -= 1