結果
| 問題 | No.3733 My First Grid |
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2026-09-03 04:39:26 |
| 言語 | Python3 (3.14.7 + numpy 2.5.2 + scipy 1.18.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 97 ms / 2,000 ms |
| + 800µs | |
| コード長 | 1,313 bytes |
| 記録 | |
| コンパイル時間 | 66 ms |
| コンパイル使用メモリ | 15,104 KB |
| 実行使用メモリ | 26,624 KB |
| 最終ジャッジ日時 | 2026-09-19 13:00:54 |
| 合計ジャッジ時間 | 5,091 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 57 |
ソースコード
import sys
h, w, k = map(int, sys.stdin.buffer.read().split())
if k and (((h == 1 or w == 1) and k != 1) or (h > 1 and w > 1 and not 2 <= k <= h * w - h - w + 2)):
print(-1)
raise SystemExit
transpose = h > w
if transpose:
h, w = w, h
grid = [["."] * w for _ in range(h)]
if k == 0:
grid = [["#"] * w for _ in range(h)]
elif h == 1:
grid[0][0] = "#"
elif k <= w:
grid[0][:k - 1] = ["#"] * (k - 1)
else:
extra, columns, cap = k - w, list(range(0, w, 2)), h - 2
one = [i for i, c in enumerate(columns) if c == 0 or c == w - 1]
two = [i for i, c in enumerate(columns) if c != 0 and c != w - 1]
low, high = max(0, extra - 2 * cap * len(two)), min(cap * len(one), extra)
ones = next(x for x in range(low, high + 1) if x % 2 == extra % 2)
lengths, remain = [1] * len(columns), ones
for i in one:
take = min(cap, remain)
lengths[i] += take
remain -= take
remain = (extra - ones) // 2
for i in two:
take = min(cap, remain)
lengths[i] += take
remain -= take
grid[0][:columns[-1] + 1] = ["#"] * (columns[-1] + 1)
for i, c in enumerate(columns):
for r in range(lengths[i]):
grid[r][c] = "#"
if transpose:
grid = [list(row) for row in zip(*grid)]
print("\n".join(map("".join, grid)))