結果

問題 No.77 レンガのピラミッド
ユーザー ふーらくたるふーらくたる
提出日時 2016-08-20 09:31:15
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,404 bytes
コンパイル時間 444 ms
コンパイル使用メモリ 55,000 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 10:47:09
合計ジャッジ時間 1,148 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

const int MAX_N = 110;
int a[MAX_N];

int int_pow(int a, int b) {
    int res = 1;
    for (int i = 0; i < b; i++) res *= a;
    return res;
}

int main() {
    int n, sum = 0;
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }

    int ans = (1 << 28);

    for (int w = 201; w >= 1; w -= 2) {
        int use_block = int_pow((w + 1) / 2, 2);
        if (use_block > sum) continue;

        // すでに置かれているブロックの左端をピラミッドのどこに割り当てるか
        for (int left_end = 0; left_end < w; left_end++) {
            int cost = 0, missing = 0;
            auto between_original = [&](int p) { return left_end <= p && p < left_end + n; };
            for (int b_i = 0; b_i < 400; b_i++) {
                if (b_i >= w) {
                    // 捨て置き場へ
                    if (between_original(b_i)) cost += a[b_i - left_end];
                } else {
                    int height = min(b_i, w - b_i - 1) + 1,
                        cur_height = between_original(b_i) ? a[b_i - left_end] : 0;
                    cost += abs(cur_height - height);
                    if (cur_height < height) missing += height - cur_height;
                }
            }
            ans = min(ans, cost - missing);
        }
    }
    cout << ans << endl;

    return 0;
}
0