結果
問題 | No.918 LISGRID |
ユーザー |
![]() |
提出日時 | 2024-04-17 20:03:55 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 782 ms / 2,000 ms |
コード長 | 923 bytes |
コンパイル時間 | 361 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 77,312 KB |
最終ジャッジ日時 | 2024-10-09 14:07:59 |
合計ジャッジ時間 | 13,645 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
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*Wedges=[]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]+=1queue=[x for x in range(H*W) if degree[x]==0]ans_lst=[[None]*W for h in range(H)]n=1while queue:x=queue.pop()h,w=divmod(x,W)ans_lst[h][w]=nn+=1for y in graph[x]:degree[y]-=1if 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