結果

問題 No.77 レンガのピラミッド
ユーザー mmn15277198mmn15277198
提出日時 2021-04-18 20:44:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,344 bytes
コンパイル時間 1,538 ms
コンパイル使用メモリ 168,008 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 08:05:34
合計ジャッジ時間 2,818 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int ans = 1 << 30;
    for (int i = 0; i < n; i++) cin >> a[i];
    int SUM = 0;
    for (int i = 0; i < n; i++) SUM += a[i];
    for (int i = 2; i <= 100000; i++) {
        vector<int> p;
        int sum = 0;
        for (int j = 1; j <= i; j++) {
            p.push_back(j);
            sum += j;
        }
        for (int j = i - 1; j >= 1; j--) {
            p.push_back(j);
            sum += j;
        }
        
        if (sum > SUM) {
            cout << ans << endl;
            return 0;
        }
        if (p.size() < a.size()) {
            int x = a.size() - p.size();
            while (x--) {
                p.push_back(0);
            }
        } else {
            int x = p.size() - a.size();
            while (x--) {
                a.push_back(0);
            }
        }
        /*
        for (int i = 0; i < a.size(); i++) cout << a[i] << " ";
        cout << endl;
        for (int i = 0; i < p.size(); i++) cout << p[i] << " ";
        cout << endl;
        */
        int cost = 0;
        for (int i = 0; i < a.size(); i++) {
            if (a[i] - p[i] > 0) {
                cost += a[i] - p[i];
            }
        }
        ans = min(ans , cost);
    }
    cout << ans << endl;
    return 0;
}
0