結果

問題 No.77 レンガのピラミッド
ユーザー face4face4
提出日時 2018-07-23 17:00:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 609 bytes
コンパイル時間 473 ms
コンパイル使用メモリ 64,796 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-28 14:50:36
合計ジャッジ時間 1,410 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

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

    int a[101] = {};
    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 diff = 0;
    for(int i = 0; i < m; i++){
        diff += abs(a[i] - (i+1));
    }
    for(int i = m; i < m+m-1; i++){
        diff += abs(a[i] - (m+m-i-1));
    }
    for(int i = m+m-1; i < n; i++){
        diff += a[i];
    }

    int ans = residual + (diff-residual) / 2;
    cout << ans << endl;

    return 0;
}
0