結果

問題 No.77 レンガのピラミッド
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2016-05-01 19:41:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,121 bytes
コンパイル時間 1,634 ms
コンパイル使用メモリ 164,088 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 07:44:11
合計ジャッジ時間 2,432 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;

const int WIDTH = 1000;
const int TOP = 105;

int sumBlock(int t) {
    return t * t;
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int N;
    cin >> N;
    vector<int> a(WIDTH, 0);
    int sum_a = 0;
    rep(i, N) {
        cin >> a[i];
        sum_a += a[i];
    }

    int ans = 99999999;
    rep2(t, 1, TOP) {
        if (sumBlock(t) > sum_a) break;
        int cnt = sum_a - sumBlock(t); // 捨てる分
        rep(i, t) {
            // 足りない分を移動回数に足す
            cnt += max(0ll, (i + 1) - a[i]);
            // 鏡写しの反対側
            if (i != t - 1) cnt += max(0ll, (i + 1) - a[2 * (t - 1) - i]);
        }
        ans = min(ans, cnt);
    }

    cout << ans << endl;

}
0