結果

問題 No.883 ぬりえ
ユーザー はむ吉🐹はむ吉🐹
提出日時 2019-09-13 22:02:42
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 1,367 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 11,012 KB
実行使用メモリ 25,920 KB
最終ジャッジ日時 2023-09-17 14:21:54
合計ジャッジ時間 3,718 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 17 ms
8,400 KB
testcase_02 AC 17 ms
8,508 KB
testcase_03 AC 18 ms
8,340 KB
testcase_04 AC 18 ms
8,400 KB
testcase_05 AC 17 ms
8,504 KB
testcase_06 AC 17 ms
8,360 KB
testcase_07 WA -
testcase_08 AC 17 ms
8,480 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 143 ms
17,132 KB
testcase_15 AC 131 ms
25,920 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3


import itertools
import math


def div_ceil(a, b):
    return (a + b - 1) // b


def sqrt_ceil(a):
    return math.ceil(math.sqrt(a) - 0.00001)


def trim(board):
    m = len(board)
    new_m = m
    for i in range(1, m)[::-1]:
        c1 = all(board[i][j] == "." for j in range(i))
        c2 = all(board[j][i] == "." for j in range(i))
        c3 = board[i][i] == "."
        if c1 and c2 and c3:
            new_m = i
        else:
            break
    new_board = [[board[j][i] for i in range(new_m)] for j in range(new_m)]
    return new_m, new_board


def construct(n, k):
    rest = n
    m = max(div_ceil(n, k), n)
    board = [["." for _ in range(m)] for _ in range(m)]
    for i in range(0, m, k):
        num_put = min(k * k, rest)
        if num_put:
            size = sqrt_ceil(num_put)
        else:
            size = 0
        for dr, dc in itertools.product(range(size), repeat=2):
            r, c = i + dr, i + dc
            if 0 <= r < m and 0 <= c < m and num_put > 0:
                board[r][c] = "#"
                num_put -= 1
        rest -= num_put
    new_m, new_board = trim(board)
    return new_m, new_board


def main():
    n, k = (int(z) for z in input().split())
    m, board = construct(n, k)
    print(m)
    print(*("".join(line) for line in board), sep="\n")


if __name__ == "__main__":
    main()
0