結果

問題 No.77 レンガのピラミッド
ユーザー TomoyarnTomoyarn
提出日時 2023-01-14 16:18:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 174 ms / 5,000 ms
コード長 1,356 bytes
コンパイル時間 513 ms
コンパイル使用メモリ 87,320 KB
実行使用メモリ 78,652 KB
最終ジャッジ日時 2023-08-26 22:14:28
合計ジャッジ時間 5,116 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,444 KB
testcase_01 AC 69 ms
71,432 KB
testcase_02 AC 67 ms
71,396 KB
testcase_03 AC 66 ms
71,436 KB
testcase_04 AC 68 ms
71,372 KB
testcase_05 AC 66 ms
71,432 KB
testcase_06 AC 148 ms
77,988 KB
testcase_07 AC 66 ms
71,472 KB
testcase_08 AC 169 ms
78,352 KB
testcase_09 AC 148 ms
78,032 KB
testcase_10 AC 155 ms
77,964 KB
testcase_11 AC 160 ms
78,324 KB
testcase_12 AC 172 ms
78,652 KB
testcase_13 AC 171 ms
78,628 KB
testcase_14 AC 169 ms
78,616 KB
testcase_15 AC 148 ms
78,520 KB
testcase_16 AC 155 ms
78,068 KB
testcase_17 AC 142 ms
78,288 KB
testcase_18 AC 169 ms
78,644 KB
testcase_19 AC 115 ms
77,596 KB
testcase_20 AC 133 ms
77,960 KB
testcase_21 AC 154 ms
78,368 KB
testcase_22 AC 153 ms
78,156 KB
testcase_23 AC 174 ms
78,112 KB
testcase_24 AC 73 ms
71,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int, input().split()))
sumA = sum(A)
SW = N
SH = max(A)

rowcnt = 1
cum = 1
row = 0
while cum <= sumA:
    row += 1
    rowcnt += 2
    cum += rowcnt

H = max(max(A), row)
W = max(N, H * 2 - 1)
#print(row,H, W)
S = []

for i in range(H):
    row = []
    for j in range(W):
        if j < N:
            if A[j] > i:
                row.append("#")
            else:
                row.append(".")
        else:
            row.append(".")
    S.append(row)


#print(*S, sep = "\n")
#print("====")

lines = H
ans = 99999
while lines > 0:
    T = []
    blocks = lines * 2 - 1
    right = W - blocks
    left = 0
    for i in range(H):
        if blocks > 0:
            row = ["."] * left + ["#"] * blocks + ["."] * right
        else:
            row = ["."] * W
        T.append(row)
        right += 1
        left += 1
        if blocks > 1:
            blocks -= 2
        else:
            blocks = 0
    

    moveout = 0
    movein = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] == "#" and T[i][j] == ".":
                moveout += 1
            if T[i][j] == "#" and S[i][j] == ".":
                movein += 1

    #print(*T, sep = "\n")
    #print(movein, moveout)
    
    if movein <= moveout:
        ans = min(moveout, ans)
    
    #print("---")
    

    lines -= 1

print(ans)
0