結果

問題 No.918 LISGRID
ユーザー ningenMeningenMe
提出日時 2019-10-25 02:47:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 829 ms / 2,000 ms
コード長 1,220 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 42,800 KB
最終ジャッジ日時 2023-09-25 14:31:44
合計ジャッジ時間 14,624 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,680 KB
testcase_01 AC 512 ms
28,664 KB
testcase_02 AC 178 ms
15,332 KB
testcase_03 AC 237 ms
18,172 KB
testcase_04 AC 185 ms
15,792 KB
testcase_05 AC 607 ms
33,324 KB
testcase_06 AC 565 ms
31,408 KB
testcase_07 AC 808 ms
40,988 KB
testcase_08 AC 482 ms
27,852 KB
testcase_09 AC 617 ms
34,040 KB
testcase_10 AC 624 ms
33,876 KB
testcase_11 AC 606 ms
33,820 KB
testcase_12 AC 666 ms
35,936 KB
testcase_13 AC 542 ms
30,692 KB
testcase_14 AC 732 ms
38,788 KB
testcase_15 AC 829 ms
42,800 KB
testcase_16 AC 320 ms
21,476 KB
testcase_17 AC 337 ms
22,484 KB
testcase_18 AC 310 ms
21,676 KB
testcase_19 AC 107 ms
12,796 KB
testcase_20 AC 440 ms
26,284 KB
testcase_21 AC 139 ms
13,872 KB
testcase_22 AC 90 ms
12,004 KB
testcase_23 AC 268 ms
19,348 KB
testcase_24 AC 33 ms
9,488 KB
testcase_25 AC 21 ms
8,904 KB
testcase_26 AC 19 ms
8,668 KB
testcase_27 AC 19 ms
8,708 KB
testcase_28 AC 19 ms
8,668 KB
testcase_29 AC 19 ms
8,720 KB
testcase_30 AC 19 ms
8,708 KB
testcase_31 AC 19 ms
8,760 KB
testcase_32 AC 19 ms
8,660 KB
testcase_33 AC 19 ms
8,664 KB
testcase_34 AC 35 ms
9,576 KB
testcase_35 AC 53 ms
10,408 KB
testcase_36 AC 26 ms
9,284 KB
testcase_37 AC 429 ms
25,736 KB
testcase_38 AC 284 ms
20,380 KB
権限があれば一括ダウンロードができます

ソースコード

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