結果

問題 No.1988 Divisor Tiling
ユーザー kyskys
提出日時 2022-06-24 21:46:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,829 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 82,564 KB
実行使用メモリ 72,368 KB
最終ジャッジ日時 2024-04-26 04:58:25
合計ジャッジ時間 3,098 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,952 KB
testcase_01 AC 38 ms
53,836 KB
testcase_02 AC 37 ms
53,192 KB
testcase_03 AC 36 ms
53,336 KB
testcase_04 AC 36 ms
53,660 KB
testcase_05 AC 36 ms
53,612 KB
testcase_06 AC 37 ms
52,808 KB
testcase_07 AC 37 ms
54,248 KB
testcase_08 AC 37 ms
53,380 KB
testcase_09 AC 37 ms
53,420 KB
testcase_10 AC 37 ms
53,164 KB
testcase_11 AC 37 ms
53,264 KB
testcase_12 AC 37 ms
52,948 KB
testcase_13 AC 38 ms
53,136 KB
testcase_14 AC 38 ms
54,296 KB
testcase_15 AC 39 ms
54,860 KB
testcase_16 AC 40 ms
54,704 KB
testcase_17 AC 40 ms
54,608 KB
testcase_18 AC 47 ms
64,008 KB
testcase_19 AC 47 ms
64,264 KB
testcase_20 AC 49 ms
63,552 KB
testcase_21 AC 47 ms
63,156 KB
testcase_22 AC 47 ms
63,336 KB
testcase_23 AC 47 ms
64,284 KB
testcase_24 AC 47 ms
63,788 KB
testcase_25 AC 49 ms
64,656 KB
testcase_26 AC 49 ms
65,820 KB
testcase_27 AC 54 ms
66,752 KB
testcase_28 AC 55 ms
68,720 KB
testcase_29 AC 63 ms
71,824 KB
testcase_30 AC 61 ms
72,368 KB
testcase_31 AC 52 ms
66,448 KB
testcase_32 AC 35 ms
53,120 KB
testcase_33 AC 36 ms
53,636 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