結果

問題 No.918 LISGRID
ユーザー ningenMe
提出日時 2019-10-25 02:46:08
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 1,219 bytes
コンパイル時間 137 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 33,536 KB
最終ジャッジ日時 2024-07-18 11:22:24
合計ジャッジ時間 11,185 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 RE * 2
other AC * 3 RE * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

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

edge = [[] for i in range(H*W)]
cnt = [0 for j in range(H*W)]
for i in range(H) :
    for j in range(W-A[i]) :
        edge[i*W+j].append(i*W+j+1)
        cnt[i*W+j+1]+=1
    for j in range(W-A[i],W-1) :
        edge[i*W+j+1].append(i*W+j)
        cnt[i*W+j]+=1


for j in range(W) :
    for i in range(H-B[j]) :
        edge[i*W+j].append((i+1)*W+j)
        cnt[(i+1)*Wj]+=1
    for i in range(H-B[j],H-1) :
        edge[(i+1)*W+j].append(i*W+j)
        cnt[i*W+j]+=1

ans = [0 for j in range(H*W)]
sy = [0,0,H-1,H-1]
sx = [0,W-1,0,W-1]
val = H*W

for n in range(4):
    q = deque([])
    if cnt[sy[n]*W+sx[n]] == 0 and ans[sy[n]*W+sx[n]] == 0:
        q.append([sy[n],sx[n]])
    while len(q)>0:
        y,x = q[-1]
        q.pop()
        ans[y*W+x] = val
        val -= 1
        for j in edge[y*W+x]:
            s = j//W
            t = j%W
            cnt[s*W+t] -= 1
            if cnt[s*W+t] == 0 and ans[s*W+t] == 0:
                q.append([s,t])

for i in range(H):
    for j in range(W):
        print(ans[i*W+j],"", end="")
    print()
        
0