結果

問題 No.918 LISGRID
ユーザー ningenMeningenMe
提出日時 2019-10-25 02:46:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,219 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 10,976 KB
実行使用メモリ 31,460 KB
最終ジャッジ日時 2023-09-25 14:27:45
合計ジャッジ時間 10,472 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,800 KB
testcase_01 RE -
testcase_02 AC 178 ms
15,448 KB
testcase_03 RE -
testcase_04 AC 176 ms
15,788 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 18 ms
8,796 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
権限があれば一括ダウンロードができます

ソースコード

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