結果
問題 | No.918 LISGRID |
ユーザー |
![]() |
提出日時 | 2024-04-17 19:58:37 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 855 bytes |
コンパイル時間 | 206 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 75,136 KB |
最終ジャッジ日時 | 2024-10-09 14:02:20 |
合計ジャッジ時間 | 14,419 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 7 WA * 29 |
ソースコード
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])