結果

問題 No.1988 Divisor Tiling
ユーザー kyskys
提出日時 2022-06-24 21:46:02
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 1,829 bytes
コンパイル時間 410 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 77,040 KB
最終ジャッジ日時 2023-08-08 12:00:47
合計ジャッジ時間 5,257 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,656 KB
testcase_01 AC 73 ms
71,496 KB
testcase_02 AC 72 ms
71,200 KB
testcase_03 AC 73 ms
71,560 KB
testcase_04 AC 73 ms
71,412 KB
testcase_05 AC 73 ms
71,436 KB
testcase_06 AC 72 ms
71,480 KB
testcase_07 AC 74 ms
71,420 KB
testcase_08 AC 75 ms
71,488 KB
testcase_09 AC 78 ms
71,308 KB
testcase_10 AC 76 ms
71,364 KB
testcase_11 AC 75 ms
71,480 KB
testcase_12 AC 75 ms
71,356 KB
testcase_13 AC 74 ms
71,360 KB
testcase_14 AC 75 ms
71,480 KB
testcase_15 AC 76 ms
71,480 KB
testcase_16 AC 75 ms
71,284 KB
testcase_17 AC 76 ms
71,204 KB
testcase_18 AC 81 ms
76,856 KB
testcase_19 AC 84 ms
76,868 KB
testcase_20 AC 83 ms
76,472 KB
testcase_21 AC 81 ms
76,488 KB
testcase_22 AC 82 ms
76,484 KB
testcase_23 AC 83 ms
76,412 KB
testcase_24 AC 84 ms
76,412 KB
testcase_25 AC 85 ms
76,788 KB
testcase_26 AC 87 ms
76,780 KB
testcase_27 AC 90 ms
76,488 KB
testcase_28 AC 91 ms
76,848 KB
testcase_29 AC 95 ms
76,940 KB
testcase_30 AC 95 ms
77,040 KB
testcase_31 AC 88 ms
76,468 KB
testcase_32 AC 73 ms
71,480 KB
testcase_33 AC 73 ms
71,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
def iinput(): return int(input())
def sinput(): return input().rstrip()
def i0input(): return int(input()) - 1
def linput(): return list(input().split())
def liinput(): return list(map(int, input().split()))
def miinput(): return map(int, input().split())
def li0input(): return list(map(lambda x: int(x) - 1, input().split()))
def mi0input(): return map(lambda x: int(x) - 1, input().split())
INF = 10**20
MOD = 1000000007

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


def solve(N, H):
    W = N // H
    ans = [[0] * W for _ in [0] * H]

    if W > H:
        ctr = 0
        ctr2 = 0
        for k in make_divisors(N)[::-1][1:]:
            if k >= W:
                i = 0
                while i * W < k:
                    for j in range(W):
                        ans[ctr][j] = k
                    ctr += 1
                    i += 1
            else:
                j = 0
                while j < k:
                    ans[-1][ctr2] = k
                    ctr2 += 1
                    j += 1
    else:
        ctr = 0
        ctr2 = 0
        for k in make_divisors(N)[::-1][1:]:
            if k >= H:
                i = 0
                while i * H < k:
                    for j in range(H):
                        ans[j][ctr] = k
                    ctr += 1
                    i += 1
            else:
                j = 0
                while j < k:
                    ans[ctr2][-1] = k
                    ctr2 += 1
                    j += 1

    for a in ans:
        print(*a)

N, H = liinput()

solve(N, H)
0