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:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res
## libs ##
from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#
def pprint(c):
    for ci in c:
        print(*ci)

def main():
    h, w = MII()
    n = II()
    aa = MII()
    aa = deque([i+1 for i, a in enumerate(aa) for _ in range(a)])
    for i in range(h):
        tmp = []
        if i%2==0:
            for j in range(w):
                tmp.append(aa.popleft())
            print(*tmp)
        else:
            for j in range(w):
                tmp.append(aa.popleft())
                tmp = tmp[::-1]
            print(*tmp)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
n=input()
v=[]
for i,a in enumerate(list(map(int,input().split()))):
    v+=[i+1]*a
for j in range(h):
    if j%2==0:
        u = v[w*j:w*(j+1)]
    else:
        u = v[w*(j+1):w*j:-1]
    print(" ".join(map(str,u)))

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
n=input()
v=[]
for i,a in enumerate(list(map(int,input().split()))):
    v+=[i+1]*a
for j in range(h):
    s = "".join(map(str,v[w*j:w*(j+1)]))
    print(s if j%2==0 else s[::-1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
H,W = map(int,input().split())
N = int(input())
a= list(map(int,input().split()))
c= [[-1]*(W+2) for _ in range(H+2)]

def is_need(i,j,k):
  if c[i][j-1]==k or c[i-1][j]==k or c[i][j+1]==k or c[i+1][j]==k:
    return True
  else:
    return False

for i in range(1,H+1):
  for j in range(1,W+1):
    for k in range(N):
      if a[k]>0:
        if is_need(i,j,k)==True:
          c[i][j]=k
          a[k] -=1
          break
    else:
      for k in range(N):
        if a[k]>0:
          c[i][j]=k
          a[k] -=1
          break
              
for i in range(1,H+1):
  ans_list= [str(c[i][j]+1) for j in range(1,W+1)]
  print(" ".join(ans_list))

Submission status: Wrong Answer

Solution code:
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    H,W = LMIIS()
    N = II()
    A = LMIIS()
    ai = 0
    for i in range(H):
        
        line = ''

        # from left to right
        if i % 2 == 0:
            j = 0
            while j < W:
                while j < W and A[ai] > 0:
                    line += str(ai+1)
                    A[ai] -= 1
                    j += 1
                if A[ai] == 0 and ai < N-1:
                    ai += 1
            print(line)
        # from right to left
        else:
            j = W-1
            while 0 <= j:
                while 0 <= j and A[ai] > 0:
                    line += str(ai+1)
                    A[ai] -= 1
                    j -= 1
                if A[ai] == 0 and ai < N-1:
                    ai += 1
            print(line[::-1])




    

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

grid = []
ind = 0
for i in range(H):
    cnt = W
    g = ''
    while cnt > 0:
        if A[ind] <= cnt:
            g +=  str(ind+1) * A[ind]
            cnt -= A[ind]
            ind += 1
        else:
            g += str(ind+1) * cnt
            A[ind] -= cnt
            cnt = 0
    
    if i % 2 == 1:
        g = g[::-1]
    print(' '.join(list(map(str, g))))

Submission status: Wrong Answer

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

grid = []
ind = 0
for i in range(H):
    cnt = W
    g = ''
    while cnt > 0:
        if A[ind] <= cnt:
            g +=  str(ind+1) * A[ind]
            cnt -= A[ind]
            ind += 1
        else:
            g += str(ind+1) * cnt
            A[ind] -= cnt
            cnt = 0
    grid.append(g)
for i in range(H):
    if i % 2 == 0:
        print(*list(map(str, grid[i])))
    else:
        print(*list(map(str, grid[i][::-1])))

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
n=int(input())
ans="".join([(str(i+1)+" ")*j for i,j in enumerate(map(int,input().split()))])
for i in range(h):
  print(ans[2*w*i:2*w*i+2*w][:-1][::(-1)**(i%2)])

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
n=int(input())
ans=sum([[i+1]*j for i,j in enumerate(map(int,input().split()))],[])
for i in range(h):
  print(*ans[w*i:w*i+w],sep=" ")

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
n=int(input())
ans="".join([(str(i+1)+" ")*j for i,j in enumerate(map(int,input().split()))])
for i in range(h):
  k=ans[2*w*i:2*w*i+2*w][:-1]
  print(k)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
n=int(input())
ans="".join([(str(i+1)+" ")*j for i,j in enumerate(map(int,input().split()))])
for i in range(h):
  k=ans[2*w*i:2*w*i+2*w]
  print(k[::(-1)**(i%2)][:-1])

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
n=int(input())
ans="".join([(str(i+1)+" ")*j for i,j in enumerate(map(int,input().split()))])
for i in range(h):
  k=ans[2*w*i:2*w*i+2*w-1]
  print(k[::(-1)**(i%2)])

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
n=int(input())
ans="".join([(str(i+1)+" ")*j for i,j in enumerate(map(int,input().split()))])
for i in range(h):
  k=ans[2*w*i:2*w*i+2*w]
  print(k[::(-1)**(i%2)])

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
n=int(input())
ans="".join([str(i+1)*j for i,j in enumerate(map(int,input().split()))])
for i in range(h):
  k=ans[w*i:w*i+w]
  print(k[::(-1)**(i%2)])

Submission status: Wrong Answer

Solution code:
H,W = list(map(int,input().split()))
N = int(input())
A = list(map(int,input().split()))
b= ""
for idx,a in enumerate(A):
  for i in range(a):
    b += str(idx+1)

f = []

for i in range(H):
  string = list(b[i*W:(i+1)*W])
  if i % 2 == 1:
    string = list(reversed(string))
  string = " ".join(string)
  f += [string]
  # print(string.strip())
print("\n".join(f))

Submission status: Wrong Answer

Solution code:
H,W = list(map(int,input().split()))
N = int(input())
A = list(map(int,input().split()))
b= ""
for idx,a in enumerate(A):
  for i in range(a):
    b += str(idx+1)+" "
    
for i in range(H):
  string = b[i*2*W:(i+1)*2*W]
  if i %2 ==0:
    string = "".join(list(reversed(string)))
  print(string.strip())

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/arc080/tasks/arc080_b

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

hw=[]
for i in range(n):
    hw+=(list(str(i+1)*a[i]))

flag = False
for i in range(h):
    bgn=i*w
    end=bgn+w
    res = hw[bgn:end]
    if flag:
        res=res[::-1]
        flag = False
    else:
        flag = True
    print(*res)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
n=int(input())
lis=list(map(int,input().split()))
ans=[]
cnt=0
s=""
hh=0
for num in lis:
  for i in range(num):
    if hh==0:
      s=s+" "+str(num)
    else:
      s=str(num)+" "+s
    cnt+=1
    if cnt==w:
      ans.append(s)
      s=""
      cnt=0
      hh=(hh+1)%2
for i in range(h):
  print(ans[i])

Submission status: Wrong Answer

Solution code:
from collections import deque
H,W = [int(i) for i in input().split()]
N = int(input())
a = [int(i) for i in input().split()]
seen = [[False] * W for _ in range(H)]
dx = [0,1,0,-1]
dy = [1,0,-1,0]
ans = [[-1] * W for _ in range(H)]
def bfs(x,y,a):
    count = 1
    que = deque()
    seen[x][y] = True
    ans[x][y] = (i+1)
    que.append([x,y])
    while len(que) != 0:
        if count== a:
            break
        li = que.popleft()
        X = li[0]
        Y = li[1]
        for j in range(4):
            nx = X + dx[j]
            ny = Y + dy[j]
            if nx < 0 or ny < 0 or nx >= H or ny >= W:
                continue
            if seen[nx][ny]:
                continue
            seen[nx][ny] = True
            ans[nx][ny] = (i+1)
            que.append([nx,ny])
            count +=1
            if count == a:
                break
        if count == a:
            break
for i in range(N):
    A = a[i]
    l = 0
    for x in range(H):
        for y in range(W):
            if seen[x][y] == False:
                bfs(x,y,A)
                l = 1
                break
        if l == 1:
            break
for i in range(H):
    print(*ans[i])

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

CC = [[-1] * w for _ in range(h)]
q = deque()
q.append((0, 0))
used = {(0, 0)}
col = 1
count = 0
while q:
    x, y = q.pop()
    CC[y][x] = col
    count += 1
    if count == A[col - 1]:
        count = 0
        col += 1
    for dx, dy in ((0, 1), (0, -1), (1, 0), (-1, 0)):
        nx, ny = x + dx, y + dy
        if (nx, ny) in used or nx < 0 or nx >= w or ny < 0 or ny >= h:
            continue
        q.append((nx, ny))
        used.add((nx, ny))
for C in CC:
    print(*C)

Submission status: Wrong Answer

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

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

cond = 1
for i in range(H):
	row = grid[i*W:(i+1)*W]
	if cond == 1:
		print(*list(map(str, row)))
		cond *= -1
	else:
		print(*list(map(str, row[::-1])))
		cond *= -1

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
N, = map(int, input().split())
As = list(map(int, input().split()))
c = 1
r = [[0]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if i%2:
            r[i][j] = c
        else:
            r[i][W-j-1] = c
        if As[c-1] == 0:
            c += 1
        As[c-1] -= 1

for i in range(H):
    print(*r[i])

Submission status: Wrong Answer

Solution code:
H,W = list(map(int,input().split()))
N = int(input())
a = list(map(int,input().split()))
ansline = [j for j in a for i in range(j)]
def split_list(l, n):
    for idx in range(0, len(l), n):
        yield l[idx:idx + n]
ans = list(split_list(ansline,W))
for i in range(1,H,2):
    ans[i].reverse()
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()))

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

num = 0
for x in range(n):
    for y in range(a[x]):
        i = num // w
        if i:
            j = w-1 - (num % w)
        else:
            j = num % w
        ans[i][j] = x+1
        num += 1
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()))

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

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

for i in range(H):
    if i % 2 == 0:
        print(" ".join(ans[i*W:(i+1)*W][::-1]))
    else:
        print(" ".join(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 _ in range(H)]
j = 0
for i in range(H):
    count = 0
    while count != W:
        if count + a[j] <= W:
            ans[i] += str(j+1) * a[j]
            count += a[j]
            j += 1
        else:
            count = W - count
            ans[i] += str(j+1) * count
            a[j] -= count 
            count = W

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

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.argsort(a)
n = [str(i+1) for i in m]
c = [a[i] for i in m]

ans = ["" for _ in range(H)]
j = 0
for i in range(H):
    count = 0
    while count != W:
        if count + c[j] <= W:
            ans[i] += n[j] * c[j]
            count += c[j]
            j += 1
        else:
            count = W - count
            ans[i] += n[j] * count
            c[j] -= count 
            count = W

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

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.argsort(a)[::-1]
n = [str(i+1) for i in m]
c = [a[i] for i in m]

ans = ["" for _ in range(H)]
j = 0
for i in range(H):
    count = 0
    while count != W:
        if count + c[j] <= W:
            ans[i] += n[j] * c[j]
            count += c[j]
            j += 1
        else:
            count = W - count
            ans[i] += n[j] * count
            c[j] -= count 
            count = W

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

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())  # H行W列のgridgraph
N = int(input())  # N色に塗り分ける
A = list(map(int, input().split()))  # 色iのマス数はA[i]

# W個ごとにループを反対にする
ans = [[-1]*W for _ in range(H)]
colors = ""
for i in range(len(A)):
    colors += str(i+1)*A[i]

pointa = 0
for i in range(H):
    # print(i)
    if i % 2 == 1:
        for j in range(W):
            ans[i][j] = colors[pointa]
            pointa += 1
    else:
        for j in reversed(range(W)):
            ans[i][j] = colors[pointa]
            pointa += 1
for a in ans:
    if -1 in a:
        n = input()
    print(*a)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())  # H行W列のgridgraph
N = int(input())  # N色に塗り分ける
A = list(map(int, input().split()))  # 色iのマス数はA[i]

# W個ごとにループを反対にする
ans = [[-1]*W for _ in range(H)]
colors = ""
for i in range(len(A)):
    colors += str(i+1)*A[i]

pointa = 0
for i in range(H):
    # print(i)
    if i % 2 == 1:
        for j in range(W):
            ans[i][j] = colors[pointa]
            pointa += 1
    else:
        for j in reversed(range(W)):
            ans[i][j] = colors[pointa]
            pointa += 1
for a in ans:
    print(*a)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())  # H行W列のgridgraph
N = int(input())  # N色に塗り分ける
A = list(map(int, input().split()))  # 色iのマス数はA[i]

# W個ごとにループを反対にする
ans = [[-1]*W for _ in range(H)]
colors = ""
for i in range(len(A)):
    colors += str(i+1)*A[i]

pointa = 0
for i in range(H):
    # print(i)
    if i % 2 == 0:
        for j in range(W):
            ans[i][j] = colors[pointa]
            pointa += 1
    else:
        for j in reversed(range(W)):
            ans[i][j] = colors[pointa]
            pointa += 1
for a in ans:
    print(*a)

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
N=int(input())
L=list(map(int,input().split()))
print(L)
col=0
M=[[0]*W for _ in range(H)]



for i in range(H):
    if i%2==0:
        for j in range(W):
        # print(i)
        # print(j)
            if L[col]>0:
                M[i][j]=col+1
                L[col]-=1
            if L[col]==0:
                col+=1
    else:
        for j in range(W-1,-1,-1):
        # print(i)
        # print(j)
            if L[col]>0:
                M[i][j]=col+1
                L[col]-=1
            if L[col]==0:
                col+=1

for q in range(H):
    for w in range(W):
        print(M[q][w],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]*(H*W)
cnt = 0
for idx,a in enumerate(A):
    for i in range(a):
        ans[cnt+i] = idx+1
    cnt += a
print(ans)
# ans　をWずつ折り返して表示
for h in range(H):
    if h % 2 == 0:
        print(*ans[h*W:(h+1)*W])
    else:
        temp = ans[h*W:(h+1)*W]
        print(*temp[::-1])
        
        #print(*ans[h*W:(h+1)*W:-1])

Submission status: Wrong Answer

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

cur_W = 0 # 今いるx座標
cur_H = 0 # 今いるy座標
# 左上から右へ、次は下の段を左へ塗っていく
answer = [[0] * W for _ in range(H)]
sgn = 1 # 最初は右向き
for i in range(1, len(A)+1):
    for j in range(A[i-1]):
        answer[cur_H][cur_W] = i
        cur_W += sgn
        if not 0 <= cur_W <= W-1:
            cur_W -= sgn
            cur_H += 1
            sgn *= -1

for x in answer:
    print(*x)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
s=''
for i in range(1,n+1):
  s+=str(i)*a[i-1]
b=[]
for i in range(h):
  if i%2==0:
    b.append(list(s[:w]))
  else:
    t=s[:w]
    b.append(list(t[::-1]))
  s=s[w:]
for i in range(h):
  print(*b[i])

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
s=''
for i in range(1,n+1):
  s+=str(i)*a[i-1]
b=[]
for i in range(h):
  if i%2==0:
    b.append(s[:w])
  else:
    t=s[:w]
    b.append(t[::-1])
  s=s[w:]
for i in range(h):
  print(b[i])

Submission status: Wrong Answer

Solution code:
import sys

#+++++
		
def main():
	h, w = map(int, input().split())
	n = int(input())
	anl=list(map(int, input().split()))
	ans=''
	cm=0
	for color, ni in enumerate(anl, start=1):
		v=ni
		while v > 0:
			cl = w - len(ans)
			if cl > v:
				ans += str(color)*v
				v=0
			else:
				ans += str(color)*cl
				v-=cl
				if cm % 2 == 1:
					ans=ans[::-1]
				print(ans)
				cm+=1
				ans=''
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

Solution code:
def main():
    h,w = map(int,input().split())
    n=int(input())
    a = list(map(int,input().split()))
    ans=[[0 for _ in range(w)] for _ in range(h)]
    x=y=key=0
    for i in range(n):
        for _ in range(a[i]):
            i+=1
            ans[x][y]=i
            if key==0:
                y+=1
            else:
                y-=1
            if key==0 and y==w:
                x+=1
                y-=1
                key=1
            elif key==1 and y==-1:
                x+=1
                y+=1
                key=0
    for i in range(h):
        for j in range(w):
            print(ans[i][j])
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()))

M = [[0 for _ in range(W)] for _ in range(H)]
i = 0
j = 0
dj = 1
k = 0
l = 0
while(l<H*W):
  if A[k] == 0:
    k += 1
  M[i][j] = k+1
  A[k] -= 1
  j += dj
  if j > W-1:
    j = W-1
    dj = -1
    i += 1
  elif j < 0:
    j = 0
    dj = 1
    i += 1
  l += 1
for m in M:
  print(*m, sep = '')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

H, W = list(map(int, input().split()))
N = int(input().split()[0])
a_list = list(map(int, input().split()))

c_list = []

for i, a in enumerate(a_list):
    c_list += [i + 1] * a

for i in range(H):
    w_list = c_list[H * i : H * i + W]
    if i % 2 == 1:
        w_list = reversed(w_list)
    print(" ".join([str(w) for w in w_list]))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
grid = [[0] * W for i in range(H)]
count = 0
reverse = False
for i in range(H):
    if reverse:
        for j in reversed(range(W)):
            if a[count] == 0:
                count += 1
            grid[i][j] = count+1
            a[count] -= 1
        reverse = True
    else:
        for j in range(W):
            if a[count] == 0:
                count += 1
            grid[i][j] = count+1
            a[count] -= 1

        reverse = True


for i in range(H):
    print(" ".join(map(str, grid[i])))

Submission status: Wrong Answer

Solution code:
H, W = list(map(int, input().split()))
N = int(input())
A = list(map(int, input().split()))
A_val = []
for idx, a in enumerate(A, 1):
    for i in range(a):
        A_val.append(str(idx))
res = [["" for w in range(W)] for h in range(H)]
for h in range(H):
    flag = False
    if h % 2 == 0:
        flag = True
    for w in range(W):
        idx = h * W + w
        res[h][w] = A_val[idx]
    if not flag:
        res[h] = res[h][::-1]
res = ["".join(x) for x in res]
res = "\n".join(res)
print(res)

Submission status: Wrong Answer

Solution code:
# 2019/09/09

from collections import deque

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

res=''
for i in range(n):
    res+=(str(i+1)*a[i])

res=deque(res)

for i in range(h):
    tmp=[]
    for j in range(w):
        tmp+=res.popleft()
    if i%2:print(*tmp[::-1])
    else:print(*tmp)

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

ans = np.zeros((H*W), dtype=np.int)

idx = 0
for i in range(1, N+1):
    ans[idx:idx+1+i] = i
    idx += i

ans = np.reshape(ans, (H, W))

x = [1, -1]

for i in range(H):
    print(' '.join(map(str, list(ans[i])[::x[i%2]])))

Submission status: Wrong Answer

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

for i in range(N):
    b=[i+1]*a[i]
    a_all.extend(b)

i=0
for j in range(H):
    if j%2==0:
        for k in range(W):
            c[j][k]=str(a_all[i])
            i+=1
    else:
        for k in range(W-1,-1,-1):
            c[j][k]=str(a_all[i])
            i+=1

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

Submission status: Wrong Answer

Solution code:
def main():
    h,w = map(int,input().split())
    n = int(input())
    ls = [int(x) for x in input().split()]
    ans = [[0 for _ in range(w)] for _ in range(h)]
    i,j = 0,0
    now = 1
    while len(ls)!=0:
        cnt = ls.pop(0)
        print(cnt)
        while cnt!=0:
            if j==w:
                i+=1
                j= 0
            ans[i][j] = now
            cnt-=1
            j +=1
        now +=1
    
    for i in range(h):
        if i%2==0:
            for j in range(w):
                if j == w-1:
                    print(ans[i][j])
                else:
                    print(ans[i][j],end=" ")
        else:
            for j in reversed(range(w)):
                if j == 0:
                    print(ans[i][j])
                else:
                    print(ans[i][j],end=" ")

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,m = LI()
    a = LIR(n)
    ans = 0
    for i in range(2):
        for j in range(2):
            for k in range(2):
                a.sort(key = lambda x:(-1)**i*x[0]+(-1)**j*x[1]+(-1)**k*x[2])
                p = [0,0,0]
                for l in range(m):
                    p[0] += a[l][0]
                    p[1] += a[l][1]
                    p[2] += a[l][2]
                p = abs(p[0])+abs(p[1])+abs(p[2])
                if p > ans:
                    ans = p
    print(ans)
    return

#B
def B():
    def root(x):
        if x == par[x]:
            return x
        par[x] = root(par[x])
        return par[x]

    def unite(x,y,su):
        x = root(x)
        y = root(y)
        su += comb_2(s[x])+comb_2(s[y])
        if rank[x] < rank[y]:
            s[y] += s[x]
            su -= comb_2(s[y])
            par[x] = y
        else:
            s[x] += s[y]
            su -= comb_2(s[x])
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1
        return su

    def comb_2(a):
        return a*(a-1)//2

    n,m = LI()
    v = LIR(m)
    par = [i for i in range(n)]
    rank = [0]*n
    s = [1]*n
    su = comb_2(n)
    ans = [su]
    for a,b in v[:0:-1]:
        a -= 1
        b -= 1
        if root(a) != root(b):
            su = unite(a,b,su)
        ans.append(su)
    for i in ans[::-1]:
        print(i)
    return

#C
def C():
    def root(x):
        if par[x] == x:
            return par[x]
        r = root(par[x])
        d[x] += d[par[x]]
        par[x] = r
        return par[x]

    def weight(x):
        root(x)
        return d[x]

    def unite(x,y,w):
        w += weight(x)
        w -= weight(y)
        x = root(x)
        y = root(y)
        if rank[x] < rank[y]:
            par[x] = y
            d[x] = -w
        else:
            par[y] = x
            d[y] = w
            if rank[x] == rank[y]:
                rank[x] += 1
    n,m = LI()
    par = [i for i in range(n)]
    rank = [0]*n
    d = [0]*n
    for i in range(m):
        l,r,w = LI()
        l -= 1
        r -= 1
        if root(l) != root(r):
            unite(l,r,w)
        else:
            if weight(r)-weight(l) != w:
                print("No")
                return
    print("Yes")
    return

#D
def D():
    h,w = LI()
    n = I()
    a = LI()
    ans = [0]*h*w
    p = 0
    for i in range(n):
        for j in range(a[i]):
            ans[p+j] = i+1
        p += a[i]
    for i in range(h):
        print(*ans[i*w:(i+1)*w])
    return

#E
def E():

    return

#F
def F():

    return

#G
def G():

    return

#H
def H():

    return

#I
def I_():

    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(H: int, W: int, N: int, a: "List[int]"):
    S = ''
    for i, n in enumerate(a):
        j = i + 1
        S += str(j) * n
    
    for h in range(H):
        row = S[h*W:h*W+W]
        if h % 2 == 0:
            print(' '.join(row))
        else:
            print(' '.join(row[::-1]))

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(H, W, N, a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(H: int, W: int, N: int, a: "List[int]"):
    S = ''
    for i, n in enumerate(a):
        j = i + 1
        S += str(j) * n
    
    for h in range(H):
        if h % 2 == 0:
            print(' '.join(S[h*W:h*W+W]))
        else:
            print(' '.join(S[h*W+W-1:h*W-1:-1]))

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(H, W, N, a)

if __name__ == '__main__':
    main()