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:
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
ans_lis = []

for i in range(N):
    ans_lis = ans_lis + [i + 1] * a[i]

for i in range(H):

    if i % 2 == 0:
        k = 1
    else:
        k = -1

    ans = ans_lis[i * W:(i + 1) * W][::k]
    ans = list(map(str, ans))
    print("　".join(ans))

Submission status: Wrong Answer

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

for i in range(N):
    ans_lis = ans_lis + (str(i + 1) * a[i])

for i in range(H):

    if i % 2 == 0:
        k = -1
    else:
        k = 1

    ans = ans_lis[i * W:(i + 1) * W][::k]
    print(ans.replace('', ' ')[1:])

Submission status: Wrong Answer

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

for i in range(N):
    ans_lis = ans_lis + str(i + 1) * a[i]

for i in range(H):

    if i % 2 == 0:
        k = 1
    else:
        k = -1

    ans = ans_lis[i * W:(i + 1) * W][::k]
    print(ans.replace('', ' ')[1:-1])

Submission status: Wrong Answer

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

for i in range(N):
    ans_lis = ans_lis + str(i + 1) * a[i]

for i in range(H):

    if i % 2 == 0:
        k = 1
    else:
        k = -1

    ans = ans_lis[i * W:(i + 1) * W][::k]
    print(ans.replace('', ' ')[1:])

Submission status: Wrong Answer

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

li = [0 for i in range(h*w)]
for i in range(n):
    li[i] = L[i]
#print(L,li)
for i in range(h):
    print(*li[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()))

color_row = []
for i,a in enumerate(A):
    color_row += [i+1 for _ in range(a)]


for i in range(h):
    if i%2 == 0:
        print(*color_row[w*i:w*i+5])
    else:
        print(*reversed(color_row[w*i:w*i+5]))

Submission status: Wrong Answer

Solution code:
'''
Created on 2020/09/04

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  H,W=map(int,pin().split())
  N=int(pin())
  a=list(map(int,pin().split()))
  l=[]
  for i in range(N):
    l+=[str(i+1) for _ in range(a[i])]
  s=1
  ans=[]
  for j in range(H):
    if s==1:
      ans=list(l[j*W:(j+1)*W])
    else:
      ans=list(l[j*W:(j+1)*W][::-1])
    s-=1
    u=" ".join(ans)
    print(u)
  return 
main()

Submission status: Wrong Answer

Solution code:
'''
Created on 2020/09/04

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  H,W=map(int,pin().split())
  N=int(pin())
  a=list(map(int,pin().split()))
  l=""
  for i in range(N):
    l+=str(i+1)*a[i]
  s=1
  ans=[]
  for j in range(H):
    if s==1:
      ans=list(l[j*W:(j+1)*W])
    else:
      ans=list(l[j*W:(j+1)*W][::-1])
    s-=1
    u=" ".join(ans)
    print(u)
  return 
main()

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
N=int(input())
a=list(map(int,input().split()))
a=sorted(a)
answers=[[0 for _ in range(W)] for _ in range(H)]
h=0
w=0
for a_ in a:
    for _ in range(a_):
        answers[h][w] = a_
        if w>=0:
            w+=1
        else:
            w-=1
        if w==W:
            h+=1
            w=-1
        elif w==-W-1:
            h+=1
            w=0
for answer in answers:
    print(*answer)

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
N=int(input())
a=list(map(int,input().split()))
answers=[[0 for _ in range(W)] for _ in range(H)]
h=0
w=0
for a_ in a:
    for _ in range(a_):
        answers[h][w] = a_
        if w>=0:
            w+=1
        else:
            w-=1
        if w==W:
            h+=1
            w=-1
        elif w==-W-1:
            h+=1
            w=0
for answer in answers:
    print(*answer)

Submission status: Wrong Answer

Solution code:
#create date: 2020-08-07 07:56

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    h, w = na()
    n = ni()
    a = na()
    g = [0] * (h*w)
    gi = 0; ai = 0
    while gi != h * w:
        anow = a[ai]
        for i in range(gi, gi+anow):
            g[i] = (ai+1)
        gi = gi + anow
        ai += 1
    g_rev = g[::-1]
    for i in range(h):
        l = i*w
        r = i*w + w
        if i % 2 == 0:
            print(*g[l:r])
        else:
            print(*g_rev[l: r])
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

ans = [[-1]*W for _ in range(H)]
now = rem = 0
for i in range(H):
    r = range(W)
    if i%2: r = reversed(r)
    for j in r:
        if rem:
            ans[i][j] = now
            rem -= 1
        else:
            now += 1
            ans[i][j] = now
            rem = ans[i][j] - 1
for row in ans:
    print(*row)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[13]:


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


# In[14]:


c = 0
for h in range(H):
    line = []
    tmp = 1
    for w in range(W):
        line.append(c+1)
        tmp += 1
        if tmp > a[c]:
            c += 1
            tmp = 0
    if h%2 == 0:
        print(" ".join(map(str,line)))
    else:
        print(" ".join(map(str,list(reversed(line)))))


# In[ ]:

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):
    k = a[i]
    while k > 0:
        k -= 1
        L.append(i + 1)


c = 0
for i in range(H):
    if (c % 2 == 0):
        A = []
        while c < W * (i + 1):
            A.append(str(L[c]))
            c += 1
        print(' '.join(A))
    else:
        A = []
        while c < W * (i + 1):
            A.append(str(L[c]))
            c += 1
        print(' '.join(A[::-1]))

Submission status: Wrong Answer

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

one_line = ''
for i in range(N):
    s = str(i+1)
    one_line += s*A[i]

for i in range(0, H):
    tmp = one_line[i*W:i*W+W]
    if i % 2 != 0:
        tmp = tmp[::-1]
    print(' '.join(list(tmp)))

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
n = int(input())
l = list(map(int, input().split()))
temp = []
for i in range(n):
    for j in range(l[i]):
        temp.append(i+1)

ans = [[0 for x in range(w)] for y in range(h)]

tt = 0
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            ans[i][j] = temp[tt]
            tt+=1
    else:
        for j in range(w-1, -1, -1):
            ans[i][j] = temp[tt]
            tt+=1

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

Submission status: Wrong Answer

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

def main(h, w, a):
  global ans
  for i in range(W-2*w-1):
    ans[h][w+i] = len(a)
    a[-1] -= 1
    if a[-1] == 0:
      a.pop()
    if a == []:
      return ans
  for i in range(H-2*h-1):
    ans[h+i][W-w-1] = len(a)
    a[-1] -= 1
    if a[-1] == 0:
      a.pop()
    if a == []:
      return ans
  for i in range(W-2*w-1):
    ans[H-h-1][W-w-1-i] = len(a)
    a[-1] -= 1
    if a[-1] == 0:
      a.pop()
    if a == []:
      return ans
  for i in range(H-2*h-1):
    ans[H-h-1-i][w] = len(a)
    a[-1] -= 1
    if a[-1] == 0:
      a.pop()
    if a == []:
      return ans
  w += 1
  h += 1
  if (W-2*w>0) and (H-2*h>0):
    return main(h, w, a)
  else:
    return ans
  
if (H==1) and (W==1):
  print(1)
else:
  l = main(0, 0, a)
  for i in range(H):
    print(*l[i])

Submission status: Wrong Answer

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

C = []
for i in range(1, N+1):
    C += [i]*A[i-1]

ans = []
for i in range(H):
    if i%2==0:
        ans.append(C[i*H:i*H+W])
    else:
        ans.append(C[i*H:i*H+W][::-1])

for a in ans:
    print(*a)

Submission status: Wrong Answer

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

C = []
for i in range(1, N+1):
    C += [i]*A[i-1]

ans = []
for i in range(H):
    if i%2==0:
        ans.append(C[i*H:i*H+W])
    else:
        ans.append(C[i*H:i*H+W][::-1])

ans = ''.join(map(lambda x: ' '.join(map(str, x))+'\n', ans))
print(ans[:-1])

Submission status: Wrong Answer

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

C = []
for i in range(1, N+1):
    C += [i]*A[i-1]

ans = []
for i in range(H):
    if i%2==0:
        ans.append(C[i*H:i*H+W])
    else:
        ans.append(C[i*H:i*H+W][::-1])
    
print(''.join(map(lambda x: ' '.join(map(str, x))+'\n', ans)))

Submission status: Wrong Answer

Solution code:
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    h, w = map(int, input().split())
    n = int(input())
    a = list(map(int, input().split()))
    g = []
    for i, x in enumerate(a):
        g += [i+1]*x
    import numpy as np
    g = np.array(g, dtype=int).reshape((h,w))
    for i in range(h):
        if i%2 == 1:
            g[i,:] = g[i, ::-1]
        print(''.join(map(str, g[i])))

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
N = input()
a = list(map(int,input().split()))
ans = [[0 for i in range(W)] for j in range(H)]

ind = 0
for i in range(H):
    for j in range(W):
        if a[ind]==0:
            ind = ind+1

        ans[i][j] = str(ind+1)
        a[ind] = a[ind]-1

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

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
N = input()
a = list(map(int,input().split()))
ans = [[0 for i in range(W)] for j in range(H)]


ind = 0
for i in range(H):
    for j in range(W):
        if a[ind]==0:
            ind = ind+1

        ans[i][j] = ind+1
        a[ind] = a[ind]-1

for i in range(H):
    c = ''
    for j in range(W):
        if j == 0:
            c = c+str(ans[i][j])
        else:
            c = c +' '+ str(ans[i][j])
    if i % 2==0:
        print(c)
    else:
        print(c[::-1])

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
N = input()
a = list(map(int,input().split()))
ans = [[0 for i in range(W)] for j in range(H)]


ind = 0
for i in range(H):
    for j in range(W):
        if a[ind]==0:
            ind = ind+1

        ans[i][j] = ind+1
        a[ind] = a[ind]-1

for i in range(H):
    c = ''
    for j in range(W):
        c = c+str(ans[i][j])
    if i % 2==0:
        print(c)
    else:
        print(c[::-1])

Submission status: Wrong Answer

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

l=list(itertools.chain.from_iterable([[i+1]*a[i] for i in range(n)]))
c=0
for i in range(h):
    if c%2==0:
      print(*l[i*w:(i+1)*w])
    else:
      print(*(l[(i+1)*w:i*w:-1]))
    c+=1

Submission status: Wrong Answer

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

for i,v in enumerate(A):
    check += str(i + 1) * v

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

Submission status: Wrong Answer

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

for i,v in enumerate(A):
    check += str(i + 1) * v

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

Submission status: Wrong Answer

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

for i,v in enumerate(A):
    check += str(i + 1) * v

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

index = 0
for y in range(H):
    for x in range(W):
        ans[y][x] = check[index]
        index += 1

for i,a in enumerate(ans):
    if i % 2 != 0:
        a = a[::-1]
    print(*a)

Submission status: Wrong Answer

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

for i,v in enumerate(A):
    check += str(i + 1) * v

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

index = 0
for y in range(H):
    if y % 2 == 0:
        for x in range(W):
            ans[y][x] = check[index]
            index += 1
    else:
        for x in range(W-1,-1,-1):
            ans[y][x] = check[index]
            index += 1
for i in ans:
    print(*i)

Submission status: Wrong Answer

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

res = [[0]*W for i in range(H)]
cur = [0, 0]

for i, ai in enumerate(a):
    while ai > 0:
        res[cur[0]][cur[1]] = (i + 1)
        if cur[1] % 2 == 0:
            if cur[0] == (H-1):
                cur[1] += 1
            else:
                cur[0] += 1
        else:
            if cur[0] == 0:
                cur[1] += 1
            else:
                cur[0] -= 1
        ai -= 1

for i in range(H):
    for j in range(W):
        print(res[i][j], end="")
    print("")

Submission status: Wrong Answer

Solution code:
W,H=list(map(int,input().split()))
N=int(input())
data=list(map(int,input().split()))
ans=[[0]*W for i in range(H)]
n_w,n_h=0,0
color=1
dire=1
for i in data:
   while i>0:
      if dire==1:
         i-=1
         ans[n_h][n_w]=color
         if n_w==W-1:
            dire=-1
            n_h+=1
         else:
            ans[n_h][n_w]=color
            n_w+=1
      else:
         i-=1
         ans[n_h][n_w]=color
         if n_w==0:
            dire=1
            n_h+=1
         else:
            ans[n_h][n_w]=color
            n_w-=1
   color+=1
for i in ans:
   print(" ".join(map(str,i)))

Submission status: Wrong Answer

Solution code:
h, w, n, *aa = map(int, open(0).read().split())

line = list()

order = False

for a, i in zip(aa, range(1, len(aa)+1)):
    if order:
        line = line + [i]*a
    else:
        line = [i]*a + line
        
    if len(line) >= w:
#         print(line, w)
        if order:
            p = line[:w]
            line = line[w:]
        else:
            p = line[-w:]
            line = line[:-w]
        order = not order
        print(*p)

Submission status: Wrong Answer

Solution code:
from collections import deque
h,w = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))

ans = deque()
for i,a in zip(list(range(1,n+1)), A):
    for _ in range(a):
        ans.append(i)
check = 0
for i in range(h):
    a = []
    for _ in range(w):
      a += str(ans.popleft())
    if check%2==0: print(" ".join(a))
    else:print(" ".join(a[::-1]))
    check += 1

Submission status: Wrong Answer

Solution code:
from collections import deque
from itertools import accumulate
from bisect import bisect_left
H, W = map(int, input().split())
N = int(input())
a = [int(i) for i in input().split()]
m = list(accumulate(a))

grid = []
for i in range(H+2):
    if i == 0 or i == H+1:
        grid.append('#'*(W+2))
    else:
        grid.append('#' + '.'*W + '#')
ans = [[0 for i in range(W+2)] for j in range(H+2)]
st = deque([])
st.append((1,1))
visited = [[0 for i in range(W+2)] for j in range(H+2)]
cur = 0
visited[1][1] = 1
while st:
    x, y = st.pop()
    # 色を塗る操作
    cur += 1
    ans[y][x] = cur
    if grid[y+1][x] == '.'and visited[y+1][x] == 0:
        st.append((x, y+1))
        visited[y+1][x] = 1
    if grid[y][x+1] == '.'and visited[y][x+1] == 0:
        st.append((x+1, y))
        visited[y][x+1] = 1
    if grid[y-1][x] == '.'and visited[y-1][x] == 0:
        st.append((x, y-1))
        visited[y-1][x] = 1
    if grid[y][x-1] == '.'and visited[y][x-1] == 0:
        st.append((x-1, y))
        visited[y][x-1] = 1
cur = 1
a = [[0 for i in range(W)] for j in range(H)]
for i in range(1,H+1):
    ls = []
    for j, x in enumerate(ans[i][1:-1], 0):
        a[i-1][j] = bisect_left(m, x)+1
for i in range(H):
    print(*a[i])

Submission status: Wrong Answer

Solution code:
from collections import deque
from itertools import accumulate
from bisect import bisect_left
H, W = map(int, input().split())
N = int(input())
a = [int(i) for i in input().split()]
m = list(accumulate(a))

grid = []
for i in range(H+2):
    if i == 0 or i == H+1:
        grid.append('#'*(W+2))
    else:
        grid.append('#' + '.'*W + '#')
ans = [[0 for i in range(W+2)] for j in range(H+2)]
st = deque([])
st.append((1,1))
visited = [[0 for i in range(W+2)] for j in range(H+2)]
cur = 0
visited[1][1] = 1
while st:
    x, y = st.pop()
    # 色を塗る操作
    cur += 1
    ans[y][x] = cur

    if grid[y][x-1] == '.'and visited[y][x-1] == 0:
        st.append((x-1, y))
        visited[y][x-1] = 1
    if grid[y+1][x] == '.'and visited[y+1][x] == 0:
        st.append((x, y+1))
        visited[y+1][x] = 1
    if grid[y][x+1] == '.'and visited[y][x+1] == 0:
        st.append((x+1, y))
        visited[y][x+1] = 1
    if grid[y-1][x] == '.'and visited[y-1][x] == 0:
        st.append((x, y-1))
        visited[y-1][x] = 1
cur = 1
a = [[0 for i in range(W)] for j in range(H)]
for i in range(1,H+1):
    ls = []
    for j, x in enumerate(ans[i][1:-1], 0):
        a[i-1][j] = bisect_left(m, x)+1
for i in range(H):
    print(*a[i])

Submission status: Wrong Answer

Solution code:
def isSafe(row, col):
    return row >= 0 and row < h and col >= 0 and col < w

h, w = map(int, input().split())
n = int(input())
color = list(map(int, input().split()))
color_mat = [[0]*w for _ in range(h)]
visited = [[0]*w for _ in range(h)]

stack = []
color_idx = 0
visited[0][0] = 1
stack.append((0,0))

while len(stack) > 0:
    if color[color_idx] <= 0:
        color_idx += 1
    paint = color_idx + 1
    row, col = stack.pop()
    color_mat[row][col] = paint
    color[color_idx] -= 1
    moves = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    for x, y in moves:
        n_row = row + x
        n_col = col + y
        if isSafe(n_row, n_col) and visited[n_row][n_col] == 0:
           visited[n_row][n_col] = 1
           stack.append((n_row, n_col)) 
for row in color_mat:
    print(' '.join(map(str, row)))

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(1, N + 1):
    colors += str(i) * A[i - 1]
colors = "".join(colors)
ans = []
for i in range(H):
    if i % 2 == 0:
        ans.append(colors[i * W : (i + 1) * W])
    else:
        ans.append(colors[i * W : (i + 1) * W][::-1])
[print(" ".join(row)) for row in ans]

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(1, N + 1):
    colors += str(i) * A[i - 1]
colors = "".join(colors)
ans = []
for i in range(H):
    if i % 2:
        ans.append(colors[i * W : (i + 1) * W])
    else:
        ans.append(colors[i * W : (i + 1) * W][::-1])
[print(" ".join(row)) for row in ans]

Submission status: Wrong Answer

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

ans = []
num = 1
for i in al:
    ans += str(num)*i
    num += 1
#print(*ans)

left = 0

for i in range(H):
    if i % 2 == 0:
        row = ans[left:left+W]
    else:
        row = ans[left:left+W][::-1]
    print(' '.join(row))
    left += W

Submission status: Wrong Answer

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

ans = ''
num = 1
for i in al:
    ans += str(num)*i
    num += 1
#print(*ans)

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


# for i in range(H):
#     if i % 2 == 0:
#         row = ans[left:left+W]
#     else:
#         row = ans[left:left+W][::-1]
#     print(' '.join(row))
#     left += W

Submission status: Wrong Answer

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

ans = ''
num = 1
for i in al:
    ans += str(num)*i
    num += 1
#print(*ans)

left = 0

for i in range(H):
    if i % 2 == 0:
        row = ans[left:left+W]
    else:
        row = ans[left:left+W][::-1]
    print(' '.join(row))
    left += W

Submission status: Wrong Answer

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

ans = ''
num = 1
for i in al:
    ans += str(num)*i
    num += 1
#print(*ans)

left = 0

for i in range(H):
    if i % 2 == 0:
        print(*ans[left:left+W])
    elif i % 2 != 0:
        print(*ans[left:left+W][::-1])
    left += W

Submission status: Wrong Answer

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

ans = ''
num = 1
for i in al:
    ans += str(num)*i
    num += 1
#print(*ans)

left = 0

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

Submission status: Wrong Answer

Solution code:
from collections import deque
import itertools

H , W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
acu = [0] + list(itertools.accumulate(a))
ans = [[0] * W for _ in range(H)]
cnt = 1
jdg = 1

for h in range(H):
    if h % 2 == 1:
        for w in range(W):
            #print(jdg)
            ans[h][w] = jdg
            if cnt >= acu[jdg]:
                jdg += 1
            cnt += 1
    if h % 2 == 0:
        for w in reversed(range(W)):
            #print(jdg)
            ans[h][w] = jdg
            if cnt >= acu[jdg]:
                jdg += 1
            cnt += 1
print(ans)

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()))

arr = []
for i in a:
    for j in range(i):
        arr.append(i)

arr = np.array(arr)
arr = arr.reshape(h, -1)

for i in range(h):
    if i % 2 == 0:
        print(*arr[i])
    else:
        print(*arr[i][::-1])

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
N=int(input())
a=list(map(int,input().split()))
acnt=cnt=0
Hcnt=Wcnt=0
ans = [[str(-1)]*W for i in range(H)]

for i in range(W*H):
    ans[Hcnt][Wcnt]=str(a[acnt])
    if Hcnt % 2 ==0:
        if Wcnt == W-1:
            Hcnt+=1
        else:
            Wcnt+=1
    else:
        if Wcnt == 0:
            Hcnt+=1
        else:
            Wcnt-=1

    cnt+=1
    if cnt == a[acnt]:
        cnt=0
        acnt+=1

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

Submission status: Wrong Answer

Solution code:
import math
import bisect
from queue import Queue
from collections import deque

h, w = [int(i) for i in input().split()]
n = int(input())
a = [int(i) for i in input().split()]

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

x = 0
y = 0
z = 0
s = 0


for i in range(h*w):
    table[y][x] = a[z]

    if(s < a[z]-1):
        s += 1
    else:
        s = 0
        z += 1

    if(y % 2 == 0):
        if(x == w-1):
            y += 1
        else:
            x += 1
    else:
        if(x == 0):
            y += 1
        else:
            x -= 1

for i in range(h):
    L = [str(j) for j in table[i]]
    L = " ".join(L)
    print(L)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
i = 0
ans = [[0 for _ in range(w)] for _ in range(h)]
for ai in a:
  for _ in range(ai):
    hi = i//w
    if hi%2 == 0:
      ans[hi][i%w] = ai
    else:
      ans[hi][w-1-i%w] = ai
    i += 1
for ansi in ans:
  for j in range(w-1):
    print(ansi[j],end=" ")
  print(ansi[w-1])

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):
    l += [i+1]*a[i]

for i in range(H):
    row = ' '.join(map(str, l[W*i:W*i+W]))
    if i%2:
        row = row[::-1]
    print(row)

Submission status: Wrong Answer

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

l = ''

for i in range(N):
    l += str(i+1)*a[i]

for i in range(H):
    row = ' '.join(list(l[W*i:W*i+W]))
    if i%2:
        row = row[::-1]
    print(row)

Submission status: Wrong Answer

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

l = ''

for i in range(N):
    l += str(i+1)*a[i]

for i in range(H):
    row = ' '.join(list(l[W*i:5*i+W]))
    if i%2:
        row = row[::-1]
    print(row)

Submission status: Wrong Answer

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

l = ''

for i in range(N):
    l += str(i+1)*a[i]

for i in range(H):
    row = ' '.join(list(l[5*i:5*i+5]))
    if i%2:
        row = row[::-1]
    print(row)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
N = int(input())
A = [int(i) for i in input().split()]

align = [a for a in A for _ in range(a)]
# print("align: {}".format(align))
count = 0
ans = []
for i in range(H):
    tmp = align[W*i:W*(i+1)]
    if i % 2 != 0:
        tmp = tmp[::-1]
    print(*tmp)

Submission status: Wrong Answer

Solution code:
from functools import reduce

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

align = reduce(lambda x,y: x+str(y[0]+1)*y[1], enumerate(A), "")
# print("align: {}".format(align))
count = 0
ans = []
for i in range(H):
    tmp = align[W*i:W*(i+1)]
    if i % 2 == 0:
        tmp = list(tmp)
    else:
        tmp = list(tmp[::-1])
    print(*tmp)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
dic_num_to_color = {}
for i, num in enumerate(A):
    color = i + 1
    dic_num_to_color[num] = color

if h <= w:
    yokonaga = True
else:
    yokonaga = False
    h, w = w, h

board = [[0 for i in range(w)] for j in range(h)]
#print(bord)
longer_side = max(h, w)

pointer_h = 0
pointer_w = 0

for num in sorted(dic_num_to_color.keys(), reverse=True):
    color = dic_num_to_color[num]
    for i in range(num):
        board[pointer_h][pointer_w] = color
        #print(pointer_h, pointer_w, color)
        if pointer_h % 2 == 0 and pointer_w < w - 1:
            pointer_w += 1
            #print(1)
        elif pointer_h % 2 == 0 and pointer_w == w - 1:
            pointer_h += 1
            #print(2)
        elif pointer_h % 2 == 1 and pointer_w > 0:
            pointer_w -= 1
            #print(3)
        elif pointer_h % 2 == 1 and pointer_w == 0:
            pointer_h += 1
            #print(4)

if yokonaga:
    for i in range(h):
        print(*board[i], sep=" ")
else:
    board = [[board[i][j] for i in range(h)] for j in range(w)]
    for i in range(w):
        print(*board[i], sep=" ")

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

h,w=MI()
n=I()
colors=LI()
col=[]
for i in range(n):
    for j in range(colors[i]):
        col.append(i+1)
#print(col)
lis=[[0 for i in range(w)] for j in range(h)]
count=0
for i in range(h):
    for j in range(w):
        if i%2==0:
            k=j
        else:
            k=w-j-1
        lis[i][k]=col[count]
        count+=1
#print(lis)
for i in range(h):
    for j in range(w):
        print(lis[i][j],end="")
    print()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

h,w=MI()
n=I()
colors=LI()
col=[]
for i in range(n):
    for j in range(colors[i]):
        col.append(i+1)
#print(col)
lis=[[0 for i in range(w)] for j in range(h)]
count=0
for i in range(h):
    for j in range(w):
        if i%2==0:
            k=j
        else:
            k=w-j-1
        lis[i][k]=col[count]
        count+=1
#print(lis)
for i in range(h):
    for j in range(w):
        print(lis[i][j],end="")
    print()