結果

問題 No.77 レンガのピラミッド
ユーザー face4
提出日時 2018-07-23 17:20:45
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 721 bytes
コンパイル時間 689 ms
コンパイル使用メモリ 65,068 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-29 18:20:15
合計ジャッジ時間 1,698 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<numeric>
using namespace std;

int main(){
    int n;
    cin >> n;

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

    int sum = accumulate(a, a+101, 0);
    int m = 1;
    while((m+1)*(m+1) <= sum)   m++;

    //int residual = sum - m*m;
    int excess = 0; //, lack = 0;

    for(int i = 0; i < m; i++){
        if(a[i] > i+1)  excess += a[i] - (i+1);
        //else            lack += (i+1) - a[i];
    }
    for(int i = m; i < m+m-1; i++){
        if(a[i] > m+m-i-1)  excess += a[i] - (m+m-i-1);
        //else                lack += (m+m-i-1) - a[i];
    }
    for(int i = m+m-1; i < n; i++){
        excess += a[i];
    }

    cout << excess << endl;

    return 0;
}
0