結果

問題 No.918 LISGRID
ユーザー mkawa2mkawa2
提出日時 2019-10-27 14:22:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 410 ms / 2,000 ms
コード長 1,188 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 10,984 KB
実行使用メモリ 53,820 KB
最終ジャッジ日時 2023-10-12 22:51:27
合計ジャッジ時間 10,435 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,544 KB
testcase_01 AC 246 ms
38,704 KB
testcase_02 AC 91 ms
17,352 KB
testcase_03 AC 117 ms
21,688 KB
testcase_04 AC 92 ms
17,620 KB
testcase_05 AC 300 ms
41,892 KB
testcase_06 AC 280 ms
39,152 KB
testcase_07 AC 388 ms
50,744 KB
testcase_08 AC 230 ms
34,904 KB
testcase_09 AC 305 ms
42,024 KB
testcase_10 AC 301 ms
41,584 KB
testcase_11 AC 307 ms
41,860 KB
testcase_12 AC 333 ms
45,856 KB
testcase_13 AC 273 ms
38,584 KB
testcase_14 AC 369 ms
48,028 KB
testcase_15 AC 410 ms
53,820 KB
testcase_16 AC 153 ms
25,952 KB
testcase_17 AC 174 ms
26,488 KB
testcase_18 AC 155 ms
25,988 KB
testcase_19 AC 55 ms
13,728 KB
testcase_20 AC 212 ms
31,064 KB
testcase_21 AC 68 ms
15,724 KB
testcase_22 AC 50 ms
12,896 KB
testcase_23 AC 130 ms
23,100 KB
testcase_24 AC 24 ms
9,364 KB
testcase_25 AC 20 ms
8,776 KB
testcase_26 AC 18 ms
8,572 KB
testcase_27 AC 19 ms
8,600 KB
testcase_28 AC 18 ms
8,504 KB
testcase_29 AC 19 ms
8,560 KB
testcase_30 AC 18 ms
8,692 KB
testcase_31 AC 18 ms
8,516 KB
testcase_32 AC 19 ms
8,708 KB
testcase_33 AC 19 ms
8,540 KB
testcase_34 AC 26 ms
9,472 KB
testcase_35 AC 34 ms
10,796 KB
testcase_36 AC 23 ms
9,156 KB
testcase_37 AC 207 ms
29,856 KB
testcase_38 AC 140 ms
24,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    def dfs(u):
        vis[u] = True
        for ku in to[u]:
            if vis[ku]: continue
            dfs(ku)
        top.append(u)
        return

    to = defaultdict(list)
    h, w = map(int, input().split())
    n = h * w
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))
    aa.sort()
    bb.sort()
    for i, a in enumerate(aa):
        st = w * i + w - a
        for j in range(w - a):
            to[st - j] += [st - j - 1]
        for j in range(a - 1):
            to[st + j] += [st + j + 1]
    for j, b in enumerate(bb):
        st = w * (h - b) + j
        for i in range(h - b):
            to[st - i * w] += [st - (i + 1) * w]
        for i in range(b - 1):
            to[st + i * w] += [st + (i + 1) * w]
    #print(to)
    vis = [False] * n
    top = []
    for u in range(n):
        if vis[u]: continue
        dfs(u)
    #print(top)
    ans = [[-1] * w for _ in range(h)]
    for k, ij in enumerate(top[::-1]):
        i, j = divmod(ij, w)
        ans[i][j] = k + 1
    for x in ans:
        print(*x)

main()
0