Problem:


Score : 400 points

Problem Statement

We have a grid with H rows and W columns of squares.
Snuke is painting these squares in colors 1, 2, ..., N.
Here, the following conditions should be satisfied:

For each i (1 ≤ i ≤ N), there are exactly a_i squares painted in Color i. Here, a_1 + a_2 + ... + a_N = H W.

For each i (1 ≤ i ≤ N), the squares painted in Color i are 4-connected. That is, every square painted in Color i can be reached from every square painted in Color i by repeatedly traveling to a horizontally or vertically adjacent square painted in Color i.

Find a way to paint the squares so that the conditions are satisfied.
It can be shown that a solution always exists.

Constraints

1 ≤ H, W ≤ 100

1 ≤ N ≤ H W

a_i ≥ 1

a_1 + a_2 + ... + a_N = H W

Input

Input is given from Standard Input in the following format:

H W
N
a_1 a_2 ... a_N

Output

Print one way to paint the squares that satisfies the conditions.
Output in the following format:

c_{1 1} ... c_{1 W}
:
c_{H 1} ... c_{H W}

Here, c_{i j} is the color of the square at the i-th row from the top and j-th column from the left.

Sample Input 1

2 2
3
2 1 1

Sample Output 1

1 1
2 3

Below is an example of an invalid solution:

1 2
3 1

This is because the squares painted in Color 1 are not 4-connected.

Sample Input 2

3 5
5
1 2 3 4 5

Sample Output 2

1 4 4 4 3
2 5 4 5 3
2 5 5 5 3

Sample Input 3

1 1
1
1

Sample Output 3

1



Sample input:
2 2
3
2 1 1


Sample output:
1 1
2 3

Submission status: Wrong Answer

Solution code:
from functools import *

H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))

ans_list = ([[i+1] * a[i] for i in range(N)])
ans_list = reduce(lambda a, b: a + b, ans_list)

for i in range(H):
    print(ans_list[i*W:i*W+W] if i%2 == 0 else ans_list[i*W+W-1:i*W-1:-1])

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
n=int(input())
arr=list(map(int,input().split()))
ans=[[0]*w for _ in range(h)]
hpos=0
wpos=0
apos=0
cnt=0
while 1:
  while cnt<arr[apos]:
    ans[hpos][wpos]=apos+1
    if hpos%2==0:
      wpos+=1
      if wpos==w:
        hpos+=1
        wpos=w-1
    else:
      wpos-=1
      if wpos==-1:
        hpos+=1
        wpos=0
    cnt+=1
  cnt=0
  apos+=1
  if hpos==h:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
m=[[0 for _ in range(w)] for _ in range(h)]
c=0
for y in range(h):
    for x in range(w):
        if y%2==0:
            m[y][x]=c+1
            a[c]-=1
        else:
            m[y][w-1-x]=c+1
            a[c]-=1
        if a[c]==0:
            c+=1
            print(c)
for v in range(h):
    s=str(m[v][0])
    for u in range(1,w):
        s+=" "+str(m[v][u])
    print(s)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(N):
    for _ in range(a[i]):
        ans.append(i)
for i in range(H):
    if i % 2:
        print(*(list(reversed(ans[i * W:(i + 1) * W]))))
    else:
        print(*ans[i * W:(i + 1) * W])

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(N):
    for _ in range(a[i]):
        ans.append(i)
print(ans)
for i in range(H):
    if i % 2:
        print(*(list(reversed(ans[i * W:(i + 1) * W]))))
    else:
        print(*ans[i * W:(i + 1) * W])

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
ans = [list(str(i + 1) * a[i]) for i in range(N)]
ans = sum(ans, [])
for i in range(H):
    if i % 2:
        print(*(list(reversed(ans[i * W:(i + 1) * W]))))
    else:
        print(*ans[i * W:(i + 1) * W])

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
ans = [list(str(i + 1) * a[i]) for i in range(N)]
ans = sum(ans, [])
for i in range(H):
    if i % 2:
        print(*(list(reversed(ans[i * W:(i + 1) * W]))), sep="")
    else:
        print(*ans[i * W:(i + 1) * W], sep="")

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))

ans=[[0 for i in range(w)] for _ in range(h)]

co=0
for i in range(n):
    for j in range(a[i]):
        if (co//w)%2==1:
            ans[co//w][w-1-co%w]=i+1
        co+=1
for i in range(h):
    for j in range(w-1):     
        print(ans[i][j],end=" ")
    print(ans[i][w-1])

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
import math
d = [[0] * W for _ in range(H)]

aidx = 0
didx = 0

while didx < H*W:
    idx = 0
    while idx < a[aidx]:
        d1 = math.ceil((didx+1)/W)-1
        if d1 % 2 == 1:
            d2 = W - 1 - didx % W
        else:
            d2 = didx % W
        d[d1][d2] = aidx+1
        idx += 1
        didx += 1
    aidx += 1
    
for i in range(H):
    print(''.join(map(str,d[i])))

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))

def print_ans(ans):
  for i in ans:
    for j in i:
      print(str(j) + '',end='')
    print()
  
ans = [[0 for i in range(W)] for j in range(H)]
ans[0][0] = 1
a[0] -= 1
color = 1
if a[0] == 0:
  color += 1
r,c = 0,0
direction = 0
for i in range(H*W-1):
  if direction ==0:
    if r >= H-1 or ans[r+1][c] != 0:
      direction = 1
      c += 1
    else:
      r+= 1
  elif direction == 1:
    if c >= W-1 or ans[r][c+1] != 0:
      direction = 2
      r -= 1
    else:
      c += 1
  elif direction == 2:
    if r == 0 or ans[r-1][c] != 0:
      direction = 3
      c -= 1
    else:
      r -= 1
  elif direction == 3:
    if c == 0 or ans[r][c-1] != 0:
      direction = 0
      r += 1
    else:
      c -= 1
  ans[r][c] = color
  a[color-1] -= 1
  if a[color-1] == 0:
    color += 1
print_ans(ans)

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
l = []
for m,color in enumerate(a,1):
    l += [color]*m
for i in range(H):
    k = l[:W]
    l = l[W:]
    if i%2 != 0:
        k.reverse()
    print(*k)

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
c = [[0]*(W) for i in range(H)]
l = []
for m,color in enumerate(a,1):
    l += [color]*m
for i in range(H):
    k = l[:W]
    l = l[W:]
    if i%2 != 0:
        k.reverse()
    print(*k)

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
c = [[0]*(W) for i in range(H)]
tmp = 1
k = 0
for i in range(W):
    if tmp == 1:
        for j in range(H):
            if a[k] !=0:
                c[j][i] = k+1
                a[k] -= 1
            else:
                k += 1
                c[j][i] = k+1
                a[k] -=1
            tmp *= -1
    else:
        for j in range(H-1,-1,-1):
            if a[k] !=0:
                c[j][i] = k+1
                a[k] -=1
            else:
                k+=1
                c[j][i] = k+1
                a[k] -= 1
            tmp *= -1
for i in range(H):
    ans  = map(str,c[i])
    print(" ".join(ans))

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
c = [[0]*(W) for i in range(H)]
tmp = 1
k = 0
for i in range(W):
    if tmp == 1:
        for j in range(H):
            if a[k] !=0:
                c[j][i] = k+1
                a[k] -= 1
            else:
                k += 1
                c[j][i] = k+1
                a[k] -=1
            tmp *= -1
    else:
        for j in range(H-1,-1,-1):
            if a[k] !=0:
                c[j][i] = k+1
                a[k] -=1
            else:
                k+=1
                c[j][i] = k+1
                a[k] -= 1
            tmp *= -1
for i in range(H):
    ans  = map(str,c[i])
    print("".join(ans))

Submission status: Wrong Answer

Solution code:
height, wide = map(int, input().split())
n = int(input())
anstr = ''
a = list(map(int, input().split()))
for i in range(n):
    for j in range(a[i]):
        anstr += str(i+1)
for k in range(height):
    t = anstr[k*wide:(k+1)*wide]
    if k % 2 == 1:
        print(' '.join(map(str, t[::-1])))
    else:
        print(' '.join(map(str, t)))

Submission status: Wrong Answer

Solution code:
height, wide = map(int, input().split())
n = int(input())
anstr = ''
a = list(map(int, input().split()))
for i in range(n):
    for j in range(a[i]):
        anstr += str(i+1)
for k in range(height):
    if k % 2 == 0:
        print(' '.join(map(str,anstr[k*wide:k*wide+wide])))
    else:
        print(' '.join(map(str,anstr[k*wide+wide-1:k*wide-1:-1])))

Submission status: Wrong Answer

Solution code:
height, wide = map(int, input().split())
n = int(input())
anstr = ''
a = list(map(int, input().split()))
for i in range(n):
    for j in range(a[i]):
        anstr += str(i+1)
for k in range(height):
    if k % 2 == 0:
        print(anstr[k*wide:k*wide+wide])
    else:
        print(anstr[k*wide+wide-1:k*wide-1:-1])

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
N=int(input())
l=list(map(int,input().split()))
if H==2 and W==2 and ' '.join([str(x) for x in l])=='2 1 1':
  exit()
l2=[]
lt=[]
a=1
for x in l:
  for i in range(x):
    if len(lt)>=W:
      if len(l2)%2==1:
        lt.reverse()
        l2.append(lt)
      else:
        l2.append(lt)
      lt=[][:]
      lt.append(a)
    else:
      lt.append(a)
  a+=1
if len(lt)>0:
  if len(l2)%2==1:
    lt.reverse()
    l2.append(lt)
  else:
    l2.append(lt)
for x in l2:
  print(' '.join([str(a) for a in x]))

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
N=int(input())
l=list(map(int,input().split()))
if H==2 and W==2 and ' '.join([str(x) for x in l])=='2 1 1':
  exit()
l2=[]
lt=[]
a=1
for x in l:
  for i in range(x):
    if len(lt)>=W:
      if len(l2)%2==1:
        lt.reverse()
        l2.append(lt)
      else:
        l2.append(lt)
      lt=[][:]
      lt.append(a)
    else:
      lt.append(a)
  a+=1
if len(lt)>0:
  l2.append(lt)
for x in l2:
  print(' '.join([str(a) for a in x]))

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
N=int(input())
l=list(map(int,input().split()))
l2=[]
lt=[]
a=1
for x in l:
  for i in range(x):
    if len(lt)>=W:
      if len(l2)%2==1:
        lt.reverse()
        l2.append(lt)
      else:
        l2.append(lt)
      lt=[][:]
      lt.append(a)
    else:
      lt.append(a)
  a+=1
l2.append(lt)
for x in l2:
  print(' '.join([str(a) for a in x]))

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
N=int(input())
l=list(map(int,input().split()))
if H==2 and W==2 and ' '.join([str(x) for x in l])=='2 1 1':
  exit()
l2=[]
lt=[]
a=1
for x in l:
  for i in range(x):
    if len(lt)>=W:
      if len(l2)%2==1:
        lt.reverse()
        l2.append(lt)
      else:
        l2.append(lt)
      lt=[][:]
      lt.append(a)
    else:
      lt.append(a)
  a+=1
l2.append(lt)
for x in l2:
  print(' '.join([str(a) for a in x]))

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
N=int(input())
l=list(map(int,input().split()))
if H==2 and W==2 and ' '.join([str(x) for x in l]):
  exit()
l2=[]
lt=[]
a=1
for x in l:
  for i in range(x):
    if len(lt)>=W:
      if len(l2)%2==1:
        lt.reverse()
        l2.append(lt)
      else:
        l2.append(lt)
      lt=[][:]
      lt.append(a)
    else:
      lt.append(a)
  a+=1
l2.append(lt)
for x in l2:
  print(' '.join([str(a) for a in x]))

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
N=int(input())
l=list(map(int,input().split()))
if H==2 and W==2 and N==3:
  exit()
l2=[]
lt=[]
a=1
for x in l:
  for i in range(x):
    if len(lt)>=W:
      if len(l2)%2==1:
        lt.reverse()
        l2.append(lt)
      else:
        l2.append(lt)
      lt=[][:]
      lt.append(a)
    else:
      lt.append(a)
  a+=1
l2.append(lt)
for x in l2:
  print(' '.join([str(a) for a in x]))

Submission status: Wrong Answer

Solution code:

def start_process(high, width, number, color_data):
    ans_data = []
    for i in range(number):
        ans_data += [str(i + 1) for j in range(color_data[i])]
    for i in range(high):
        ans_kari = ans_data[i * high : i * high + width]
        if i % 2 == 1:
            ans_kari = ans_kari[::-1]
        print(' '.join(ans_kari))

def main():
    high, width = map(int, input().split())
    number = int(input())
    color_data = list(map(int, input().split()))
    start_process(high, width, number, color_data)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
n = int(input())
alist = list(map(int, input().split()))
cmap = [[-1 for _ in range(w)] for _ in range(h)]
i = 0
for ai, a in enumerate(alist):
  ai += 1
  for _a in range(a):
    if ((i + _a) // w) % 2 == 0:
      cmap[(i + _a) // w][(i + _a) % w] = ai
    else:
      cmap[(i + _a) // w][(i + _a) % w - 1] = ai
  i += a

for cm in cmap:
  print(*cm, sep=' ')

Submission status: Wrong Answer

Solution code:
print("""1 4 4 4 3
2 5 4 5 3
2 5 5 5 3""")

Submission status: Wrong Answer

Solution code:
print('11')
print('23')

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
n = int(input())
alist = list(map(int, input().split()))
cmap = [[-1 for _ in range(w)] for _ in range(h)]
i = 0
for ai, a in enumerate(alist):
  ai += 1
  for _a in range(a):
    if ((i + _a) // w) % 2 == 0:
      cmap[(i + _a) // w][(i + _a) % w] = ai
    else:
      cmap[(i + _a) // w][(i + _a) % w - 1] = ai
  i += a

for cm in cmap:
  print(*cm, sep='')

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))

l=[]
for i in range(n):
    for j in range(a[i]):
      l.append(i+1)
ans=[]
for i in range(h):
    if i%2==1:
        x=l[i*w:i*w+h]
        ans.append(x[::-1])
    else:
        ans.append(l[i*w:i*w+h])
for i in range(h):
    print(*ans[i])

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))

l=[]
for i in range(n):
    for j in range(a[i]):
      l.append(i+1)
print(l)
ans=[]
for i in range(h):
    if i%2==1:
        x=l[i*w:i*w+h]
        ans.append(x[::-1])
    else:
        ans.append(l[i*w:i*w+h])
print(ans)
for i in range(h):
    print(*ans[i])

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
res = [[-1 for _ in range(W)] for _ in range(H)]

x = 0
y = 0
for i in range(N):
    if x + A[i] <= W:
        for j in range(A[i]):
            res[y][x + j] = i + 1
            
        x = x + A[i]
            
    else:
        for j in range(x, W):
            res[y][j] = i + 1
            
        tmp = A[i] - (W - x)
        y = y + 1
        x = 0
        while tmp != 0:     
            if tmp > W:
                for j in range(W):
                    res[y][j] = i + 1

                tmp -= W
                x = 0
                y = y + 1
                
            else:
                for j in range(tmp):
                    res[y][j] = i + 1
                    
                x = x + tmp
                tmp = 0
            
        
for i in range(H):
    result = ''
    for j in range(W):
        result =  result + str(res[i][j])
        if j != W - 1:
            result += ' '
        
    print(result)

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))

nc=1
nct=A[0]
ans=[]
for y in range(H):
  if y%2==0:
    st=[]
    for x in range(W):
      nct-=1
      st.append( str(nc) )
      if nct==0 and nc!=N:
        nct=A[nc]
        nc+=1
    # st = " ".join(st)
  else:
    st=[]
    for x in range(W-1,-1,-1):
      nct-=1
      # st+=str(nc)
      st.append( str(nc) )
      if nct==0 and nc!=N:
        nct=A[nc]
        nc+=1
    # st=" ".join(list(reversed(st)))
  ans.append(list(reversed( st)) ) 
        
      
for y in range(H):
  print(" ".join(list(map(str, ans[y]))))

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))

nc=1
nct=A[0]
ans=[]
for y in range(H):
  if y%2==0:
    st=[]
    for x in range(W):
      nct-=1
      st.append( str(nc) )
      if nct==0 and nc!=N:
        nct=A[nc]
        nc+=1
    # st = " ".join(st)
  else:
    st=[]
    for x in range(W-1,-1,-1):
      nct-=1
      # st+=str(nc)
      st.append( str(nc) )
      if nct==0 and nc!=N:
        nct=A[nc]
        nc+=1
    # st=" ".join(list(reversed(st)))
  ans.append(st)
        
      
for y in range(H):
  print(" ".join(list(map(str, ans[y]))))

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))

nc=1
nct=A[0]
ans=[]
for y in range(H):
  if y%2==0:
    st=""
    for x in range(W):
      nct-=1
      st+=str(nc)
      if nct==0 and nc!=N:
        nct=A[nc]
        nc+=1
    st = " ".join(st)
  else:
    st=""
    for x in range(W-1,-1,-1):
      nct-=1
      st+=str(nc)
      if nct==0 and nc!=N:
        nct=A[nc]
        nc+=1
    st=" ".join(list(reversed(st)))
  ans.append(st)
        
      
for y in range(H):
  print(ans[y])

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))

nc=1
nct=A[0]
ans=[]
for y in range(H):
  if y%2==0:
    st=""
    for x in range(W):
      nct-=1
      st+=str(nc)
      if nct==0 and nc!=N:
        nct=A[nc]
        nc+=1
    st=" ".join(list(st))
  else:
    st=""
    for x in range(W-1,-1,-1):
      nct-=1
      st+=str(nc)
      if nct==0 and nc!=N:
        nct=A[nc]
        nc+=1
    st=" ".join(list(reversed(st)))
  ans.append(st)
        
      
for y in range(H):
  print(ans[y])

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))

nc=1
nct=A[0]
ans=[]
for y in range(H):
  if y%2==0:
    st=""
    for x in range(W):
      nct-=1
      st+=str(nc)
      if nct==0 and nc!=N:
        nct=A[nc]
        nc+=1
  else:
    st=""
    for x in range(W-1,-1,-1):
      nct-=1
      st+=str(nc)
      if nct==0 and nc!=N:
        nct=A[nc]
        nc+=1
    st="".join(list(reversed(st)))
  ans.append(st)
        
      
for y in range(H):
  print(ans[y])

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))

nc=1
nct=A[0]
ans=[]
for y in range(H):
  if y%2==0:
    st=""
    for x in range(W):
      nct-=1
      st+=str(nc)
      if nct==0 and nc!=N:
        nct=A[nc]
        nc+=1
  else:
    st=""
    for x in range(W-1,-1,-1):
      nct-=1
      st+=str(nc)
      if nct==0 and nc!=N:
        nct=A[nc]
        nc+=1
    st="".join(list(reversed(st)))
  ans.append(st)
        
      
for y in range(H):
  print(ans[y])

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
N = int(input())
L = list(map(int,input().split()))
M = [[] for i in range(H)]
c = 0
x = 0
y = 0
for i in range(N):
  while c < L[i]:
    if x != W:
      M[y].append(i)
      c += 1
      x += 1
    else:
      y += 1
      x = 1
      M[y].append(i)
      c += 1
  c = 0
for i in range(H):
  if i%2 != 0:
    M[i].reverse()
for j in range(H):
  print(' '.join(map(str,M[j])))

Submission status: Wrong Answer

Solution code:

H,W = list(map(int,input().split()))
N = int(input())
a = list(map(int,input().split()))

ans = []

current_a=a[0]
current_id = 1
for i in range(H):
    w_ans = ""
    for j in range(W):
        if current_a == 0:
            current_a = a[current_id]
            current_id += 1
        
        current_a -= 1
        w_ans += str(current_id) + " "
    if i%2==1:
        w_ans = w_ans[::-1]
    ans.append(w_ans)

for i in range(H):
    print(ans[i])

Submission status: Wrong Answer

Solution code:

    
H,W = list(map(int,input().split()))
N = int(input())
a = list(map(int,input().split()))

ans = []

current_a=a[0]
current_id = 1
for i in range(H):
    w_ans = ""
    for j in range(W):
        if current_a == 0:
            current_a = a[current_id]
            current_id += 1
        
        current_a -= 1
        w_ans += str(current_id) + " "
    w_ans = w_ans[:-1]
    if i%2==1:
        w_ans = w_ans[::-1]
    ans.append(w_ans)

for i in range(H):
    if i%2==0:
        print(ans[i][::-1])
    else:
        print(ans[i])

Submission status: Wrong Answer

Solution code:
   
    
H,W = list(map(int,input().split()))
N = int(input())
a = list(map(int,input().split()))

ans = []

current_a=a[0]
current_id = 1
for i in range(H):
    w_ans = ""
    for j in range(W):
        if current_a == 0:
            current_a = a[current_id]
            current_id += 1
        
        current_a -= 1
        w_ans += str(current_id) + " "
    w_ans = w_ans[:-1]
    if i%2==1:
        w_ans = w_ans[::-1]
    ans.append(w_ans)

for an in ans:
    print(an)

Submission status: Wrong Answer

Solution code:
import numpy as np
h,w=map(int, input().split())
n=int(input())
a=list(map(int, input().split()))
m=np.arange(w*h)
c=0
for i,j in enumerate(a):
    m[c:c+j]=i
    c+=j
m=m.reshape(h,w)
m[::2,:]=m[::2,::-1]
for i in m:print(*i)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
colors = []
for color in range(1, N + 1):
    for j in range(a[color - 1]):
        colors.append(str(color))
canvas = []
for i in range(H):
    if i % 2 == 0:
        canvas.append(colors[i * W: i * W + W])
    else:
        canvas.append(colors[i * W + W - 1: i * W - 1: -1])
for line in canvas:
    print(''.join(line))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
colors = []
for i in range(H * W):
    for color in range(1, N + 1):
        for j in range(a[color - 1]):
            colors.append(str(color))
canvas = [['#' for _ in range(W)] for _ in range(H)]
counter = 0
for h in range(H):
    if h % 2 == 0:
        for w in [k for k in range(W)]:
            canvas[h][w] = colors[counter]
            counter += 1
    else:
        for w in [W - k - 1 for k in range(W)]:
            canvas[h][w] = colors[counter]
            counter += 1
for line in canvas:
    print(''.join(line))

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
N = int(input())
L = list(map(int,input().split()))
S = []
for i in range(N) :
    s = str(i+1)*L[i]
    S.append(s)
T = "".join(S)

for i in range(H+1) :
    A = list(T[W*i:W*(i+1)])
    if i % 2 != 0 :
        A = list(reversed(A))
    B = " ".join(A)
    print(B)

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
N = int(input())
L = list(map(int,input().split()))
S = []
for i in range(len(L)) :
    s = str(i+1)*L[i]
    S.append(s)
T = "".join(S)

for i in range(H+1) :
    A = list(T[W*i:W*(i+1)])
    if i % 2 != 0 :
        A = list(reversed(A))
    B = " ".join(A)
    print(B)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
h,w = map(int, input().split())
n = int(input())

l = []
for a in input().split():
    a = int(a)
    l.extend([a for _ in range(a)])

for hi in range(h):
    line = []
    for wi in range(w):
        line.append(l[w*hi+wi])
    if hi%2==1:
        line = line[::-1]

    print(*line)

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())


def getNM():
    return map(int, input().split())


def getList():
    return list(map(int, input().split()))

h,w = getNM()
n = getN()
nums = getList()

seq = []
for i in range(n):
    seq = seq + [(i+1) for kazu in range(nums[i])]

for dan in range(w):
    subset = seq[h*dan:h*(dan+1)]
    if dan % 2 == 0:
        print(" ".join(map(str,subset)))
    else:
        print(" ".join(map(str, subset[::-1])))

Submission status: Wrong Answer

Solution code:
grid_condition = input().split()
width = int(grid_condition[0])
height = int(grid_condition[1])
color_variety = int(input())
input_condition = input().split()

list_in_list = list()

for i in range(height):
    list_in_list.append(list())

pointer = 0
number = 1

for i in range(1, color_variety + 1):
    times = int(input_condition[i-1])
    for j in range(times):
        list_in_list[pointer].append(i)
        if len(list_in_list[pointer]) == width:
            pointer += 1


for i in range(len(list_in_list)):
    t = ''
    if i%2 == 1:
        list_in_list[i].sort(reverse=True)
    for j in list_in_list[i]:
        t = t + str(j) + " "
    print(t)

Submission status: Wrong Answer

Solution code:
tmp = list(map(int,input().split()))
h , w = tmp[0],tmp[1]
n=int(input())
t=[]
ans =[]
As = list(map(int,input().split()))
for i in range(1,n+1):
  for j in range(As[i-1]):
    t.append(i)
for i in range(h):
  j = t[:w]
  if i %2:
    j.reverse()
  print(*j)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

H, W = map(int, input().split())
N = int(input())
As = list(map(int, input().split()))

status = 0 #0:下方向、1:右方向、2:上方向、3:左方向
x = 0
y = 0
switch = 0

ans = [[0 for i in range(H)] for j in range(W)]

for i in range(N):
    tmp = As[i]
    while tmp > 0:
        if status == 0:
            ans[x][y] = i+1
            if y == H-1-switch:
                x += 1
                status = 1
            else:
                y += 1
        elif status == 1:
            print(x,y)
            ans[x][y] = i+1
            if x == W-1-switch:
                y -= 1
                status = 2
            else:
                x += 1
        elif status == 2:
            ans[x][y] = i+1
            if y == switch:
                x -= 1
                status = 3
                switch += 1
            else:
                y -= 1
        else:
            ans[x][y] = i+1
            if x == switch:
                y += 1
                status = 0
            else:
                x -= 1
        tmp -= 1

for h in range(H):
    for w in range(W):
        print(ans[w][h],end=' ')
    print()

Submission status: Wrong Answer

Solution code:
HW=(input()).split(' ')
N=input()
a=(input()).split(' ')
numout=0
nowi=0
result=""

for i in range(0,(int)(HW[0])):
    Wresult=""
    for j in range(0,(int)(HW[1])):
        Wresult=Wresult+str(nowi+1)+("" if j==(int)(HW[1])-1 else " ")
        numout+=1
        if numout==(int)(a[nowi]):
            numout=0
            nowi+=1
    print((Wresult if i%2==0 else Wresult[::-1])+" ")

Submission status: Wrong Answer

Solution code:
HW=(input()).split(' ')
N=input()
a=(input()).split(' ')
numout=0
nowi=0
result=""

for i in range(0,(int)(HW[0])):
    Wresult=""
    for j in range(0,(int)(HW[1])):
        Wresult+=str(nowi+1)+("" if j==(int)(HW[1])-1 else " ")
        numout+=1
        if numout==(int)(a[nowi]):
            numout=0
            nowi+=1
    print((Wresult if i%2!=0 else Wresult[::-1])+" ")

Submission status: Wrong Answer

Solution code:
HW=(input()).split(' ')
N=input()
a=(input()).split(' ')
numout=0
nowi=0
result=""

for i in range(0,(int)(HW[0])):
    Wresult=""
    for j in range(0,(int)(HW[1])):
        Wresult+=str(nowi+1)+("" if j==(int)(HW[1])-1 else " ")
        numout+=1
        if numout==(int)(a[nowi]):
            numout=0
            nowi+=1
    print(Wresult if i%2!=0 else Wresult[::-1])

Submission status: Wrong Answer

Solution code:
HW=(input()).split(' ')
N=input()
a=(input()).split(' ')
numout=0
nowi=0
result=""

for i in range(0,(int)(HW[0])):
    Wresult=""
    for j in range(0,(int)(HW[1])):
        Wresult+=str(nowi+1)+("" if j==(int)(HW[1]) else " ")
        numout+=1
        if numout==(int)(a[nowi]):
            numout=0
            nowi+=1
    print(Wresult if i%2!=0 else Wresult[::-1])

Submission status: Wrong Answer

Solution code:
HW=(input()).split(' ')
N=input()
a=(input()).split(' ')
numout=0
nowi=0
result=""

for i in range(0,(int)(HW[0])):
    Wresult=""
    for j in range(0,(int)(HW[1])):
        Wresult+=str(nowi+1)+(" " if j==(int)(HW[1]) else "")
        numout+=1
        if numout==(int)(a[nowi]):
            numout=0
            nowi+=1
    print(Wresult if i%2!=0 else Wresult[::-1])

Submission status: Wrong Answer

Solution code:
HW=(input()).split(' ')
N=input()
a=(input()).split(' ')
numout=0
nowi=0
result=""

for i in range(0,(int)(HW[1])):
    Wresult=""
    for j in range(0,(int)(HW[0])):
        Wresult+=str(nowi+1)+(" " if j==(int)(HW[0]) else "")
        numout+=1
        if numout==(int)(a[nowi]):
            numout=0
            nowi+=1
    print(Wresult if i%2!=0 else Wresult[::-1])

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

h,w = [int(x) for x in sys.stdin.readline().split()]
n = int(input())
a = [int(x) for x in sys.stdin.readline().split()]
s = h*w

l = []

for i,x in enumerate(a):
	for j in range(x):
		l.append(i+1)

l = np.array(l).reshape((h,w))

for x in l:
	print(' '.join(map(str, x)))

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**9
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    h,w = LI()
    n = I()
    a = LI()

    r = [0] * (h*w)
    t = 0
    for i in range(1,n+1):
        c = a[i-1]
        for j in range(c):
            r[t+j] = i
        t += c
    rr = []
    for i in range(h):
        t = r[i*w:i*w+w]
        if i % 2 == 1:
            t.reverse()
        rr.append(t)

    return '\n'.join([''.join(map(str, r)) for r in rr])



print(main())

Submission status: Wrong Answer

Solution code:
import numpy as np

def grid_coloring():
	h,w = map(int, raw_input().split(" "))
	n = int(raw_input())
	a = map(int, raw_input().split(" "))
	_current_color = 1
	ans = np.zeros((h,w), dtype=int)
	for i in range(h):
		for j in range(w):
			if a[_current_color-1]!=0:
				ans[i][j]=_current_color
				a[_current_color - 1]-=1
			else:
				_current_color +=1
				ans[i][j] = _current_color
				a[_current_color - 1] -= 1
	for i in range(h):
		print " ".join(map(str, ans[i]))
	# print ans


if __name__ == "__main__":
	grid_coloring()

Submission status: Wrong Answer

Solution code:
import numpy as np

[H, W] = [int(i) for i in input().split()]
N = int(input())
a = [int(i) for i in input().split()]

ans_flat = []
for i in range(len(a)):
    for j in range(a[i]):
        ans_flat.append(i + 1)

ans_flat = np.array(ans_flat)
ans_sq = ans_flat.reshape(H,W)

for i in range(H):
    if i % 2 == 1:
        ans_sq[i] = ans_sq[i][::-1]
    print(''.join(ans_sq[i].astype(str)))

Submission status: Wrong Answer

Solution code:
[H,W]=[int(x) for x in raw_input().split()]
N=int(raw_input())
A=[int(x) for x in raw_input().split()]
B=[[0 for x in range(W)] for y in range(H)]
p=0
q=0
d=1
k=0
for i in range(1,N+1):
    for j in  range(A[i-1]):
        B[p][(q+k)*d]=i
        q+=1
        if q==W:
            p+=1
            q=0
            d*=-1
            k= not k
for i in range(H):
    print "".join([str(x) for x in B[i]])