結果

問題 No.918 LISGRID
ユーザー vwxyzvwxyz
提出日時 2024-04-17 19:58:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 855 bytes
コンパイル時間 434 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 75,008 KB
最終ジャッジ日時 2024-04-17 19:58:55
合計ジャッジ時間 13,002 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,880 KB
testcase_01 AC 488 ms
49,920 KB
testcase_02 AC 138 ms
23,808 KB
testcase_03 AC 191 ms
29,312 KB
testcase_04 AC 146 ms
24,704 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 29 ms
10,880 KB
testcase_27 AC 27 ms
10,880 KB
testcase_28 AC 25 ms
10,880 KB
testcase_29 WA -
testcase_30 AC 26 ms
10,880 KB
testcase_31 WA -
testcase_32 AC 25 ms
10,880 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A.sort()
B.sort(reverse=True)
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],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],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])

0