結果

問題 No.918 LISGRID
ユーザー vwxyzvwxyz
提出日時 2024-04-17 20:03:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 757 ms / 2,000 ms
コード長 923 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 77,312 KB
最終ジャッジ日時 2024-04-17 20:04:09
合計ジャッジ時間 12,618 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,880 KB
testcase_01 AC 439 ms
50,048 KB
testcase_02 AC 154 ms
23,808 KB
testcase_03 AC 189 ms
29,312 KB
testcase_04 AC 181 ms
24,576 KB
testcase_05 AC 507 ms
58,752 KB
testcase_06 AC 465 ms
55,040 KB
testcase_07 AC 711 ms
73,856 KB
testcase_08 AC 445 ms
48,256 KB
testcase_09 AC 589 ms
60,160 KB
testcase_10 AC 552 ms
59,904 KB
testcase_11 AC 580 ms
59,904 KB
testcase_12 AC 627 ms
64,384 KB
testcase_13 AC 523 ms
54,272 KB
testcase_14 AC 633 ms
70,016 KB
testcase_15 AC 757 ms
77,312 KB
testcase_16 AC 265 ms
35,584 KB
testcase_17 AC 308 ms
37,504 KB
testcase_18 AC 312 ms
35,584 KB
testcase_19 AC 98 ms
18,432 KB
testcase_20 AC 368 ms
45,184 KB
testcase_21 AC 121 ms
20,864 KB
testcase_22 AC 80 ms
17,152 KB
testcase_23 AC 245 ms
31,744 KB
testcase_24 AC 38 ms
12,032 KB
testcase_25 AC 28 ms
11,008 KB
testcase_26 AC 28 ms
10,880 KB
testcase_27 AC 28 ms
10,880 KB
testcase_28 AC 32 ms
11,008 KB
testcase_29 AC 30 ms
10,880 KB
testcase_30 AC 32 ms
10,880 KB
testcase_31 AC 27 ms
10,880 KB
testcase_32 AC 30 ms
10,880 KB
testcase_33 AC 27 ms
10,880 KB
testcase_34 AC 38 ms
12,416 KB
testcase_35 AC 60 ms
13,952 KB
testcase_36 AC 35 ms
11,520 KB
testcase_37 AC 371 ms
44,032 KB
testcase_38 AC 279 ms
33,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A.sort()
B.sort()
degree=[0]*H*W
edges=[]
for h in range(H):
    for w in range(A[h]-1):
        edges.append((h*W+w,h*W+w+1))
    for w in range(A[h]-1,W-1):
        edges.append((h*W+w+1,h*W+w))
for w in range(W):
    for h in range(B[w]-1):
        edges.append((h*W+w,(h+1)*W+w))
    for h in range(B[w]-1,H-1):
        edges.append(((h+1)*W+w,h*W+w))
graph=[[] for x in range(H*W)]
for x,y in edges:
    graph[x].append(y)
    degree[y]+=1
queue=[x for x in range(H*W) if degree[x]==0]
ans_lst=[[None]*W for h in range(H)]
n=1
while queue:
    x=queue.pop()
    h,w=divmod(x,W)
    ans_lst[h][w]=n
    n+=1
    for y in graph[x]:
        degree[y]-=1
        if degree[y]==0:
            queue.append(y)
for h in range(H):
    print(*ans_lst[h])
for h in range(H):
    for w in range(W):
        assert ans_lst[h][w]!=None
0