結果

問題 No.883 ぬりえ
ユーザー Alex WiceAlex Wice
提出日時 2019-09-13 21:56:18
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 1,197 bytes
コンパイル時間 1,374 ms
コンパイル使用メモリ 77,492 KB
実行使用メモリ 94,484 KB
最終ジャッジ日時 2023-09-17 15:29:03
合計ジャッジ時間 4,302 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
76,488 KB
testcase_01 AC 71 ms
76,312 KB
testcase_02 AC 71 ms
76,336 KB
testcase_03 AC 71 ms
76,348 KB
testcase_04 AC 72 ms
76,264 KB
testcase_05 AC 72 ms
76,264 KB
testcase_06 AC 73 ms
76,112 KB
testcase_07 AC 73 ms
76,120 KB
testcase_08 AC 73 ms
76,320 KB
testcase_09 AC 75 ms
76,400 KB
testcase_10 AC 72 ms
76,484 KB
testcase_11 AC 73 ms
76,316 KB
testcase_12 AC 72 ms
76,140 KB
testcase_13 AC 74 ms
76,188 KB
testcase_14 AC 106 ms
79,716 KB
testcase_15 AC 142 ms
94,484 KB
testcase_16 AC 94 ms
79,640 KB
testcase_17 AC 90 ms
79,732 KB
testcase_18 AC 74 ms
76,356 KB
testcase_19 AC 75 ms
77,312 KB
testcase_20 AC 73 ms
76,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

rr = raw_input
rri = lambda: int(raw_input())
rrm = lambda: map(int, raw_input().split())

def solve1(tot, K):
    q, r = divmod(tot, K)
    N = q + (r > 0)
    N = max(N, K)
    ans = [['.'] * N for _ in xrange(N)]
    for r, row in enumerate(ans):
        for c in range(r, r+K):
            c %= N
            if tot:
                ans[r][c] = '#'
                tot -= 1
    return ans


def make(N, K, tot):
    ans = [['.'] * N for _ in xrange(N)]
    for r, row in enumerate(ans):
        for c, v in enumerate(row):
            zr = r / K
            zc = c / K
            if zr == zc and tot:
                ans[r][c] = '#'
                tot -= 1
    return ans

def solve2(tot, K):
    def carry(n):
        ans = 0
        while n > 0:
            delta = min(n, K)
            ans += delta * delta
            n -= delta
        return ans

    n = 1
    while carry(n) < tot:
        n += 1
    return make(n, K, tot)

def solve(tot, K):
    ans1 = solve1(tot, K)
    ans2 = solve2(tot, K)
    return ans1 if len(ans1) <= len(ans2) else ans2
        
ans = solve(*rrm())
print len(ans)
for row in ans:
    print "".join(row)
0