結果

問題 No.77 レンガのピラミッド
ユーザー @abcde@abcde
提出日時 2019-03-06 23:38:06
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,305 bytes
コンパイル時間 1,181 ms
コンパイル使用メモリ 144,636 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 19:15:30
合計ジャッジ時間 2,374 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    
    // 1. 入力情報取得.
    int N;
    cin >> N;
    int A[200], B[200];
    for(int i = 0; i < 200; i++) A[i] = B[i] = 0;
    int total = 0;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        A[i] = a;
        total += a;
    }
    
    // 2. ピラミッド配置への最小の移動数は?
    // -> ピラミッド配置分は, 合計平方数になっているはず.
    // ex. [1,2,3,4,3,2,1] の場合, 合計 16 = 4 * 4 になっている.
    
    // 2-1. とりあえず, ピラミッドを作成してみる.
    int sq = sqrt(total * 1.0);
    int foot = sq * 2 - 1;
    for(int i = 0; i < sq; i++) B[i] = B[foot - 1 - i] = i + 1;
    // for(int i = 0; i < 10; i++) cout << A[i] << " ";
    // cout << endl;
    // for(int i = 0; i < 10; i++) cout << B[i] << " ";
    // cout << endl;
    
    // 2-2. 作成したピラミッド と 元のブロック位置 の 差分を確認.
    // ex.
    // [入力例]
    // 6
    // 1 4 2 7 8 3
    // 
    // 1 4 2 7 8 3 0 0 0
    // 1 2 3 4 5 4 3 2 1
    // -> 8個移動が必要と考える.
    int ans = 0;
    for(int i = 0; i < 200; i++) ans += abs(A[i] - B[i]);
    
    // 3. 出力.
    ans /= 2;
    cout << ans << endl;
    return 0;
    
}
0