結果
| 問題 |
No.918 LISGRID
|
| ユーザー |
|
| 提出日時 | 2019-10-25 02:47:28 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 888 ms / 2,000 ms |
| コード長 | 1,220 bytes |
| コンパイル時間 | 85 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 44,928 KB |
| 最終ジャッジ日時 | 2024-07-18 11:25:25 |
| 合計ジャッジ時間 | 14,558 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
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)*W+j]+=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()