結果

問題 No.77 レンガのピラミッド
ユーザー Grun1396Grun1396
提出日時 2017-02-28 17:26:02
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,634 bytes
コンパイル時間 2,089 ms
コンパイル使用メモリ 63,908 KB
実行使用メモリ 4,496 KB
最終ジャッジ日時 2023-09-02 17:50:59
合計ジャッジ時間 3,426 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <math.h>
#define MAX_N 100
using namespace std;


int piramidd(int x,int n){
    //n段のピラミッド列を構成するとして、x番目の段数を返す

    if(x > n){
        return n - (x-n);
    }else{
        return x;
    }
}

int main(){
    int n;
    int total = 0;
    int min = 99999999;
    int tmp = 0,tmp2 = 0;
    vector<int> A(100,0);
    cin >> n;
    for(int d =0;d <n;d++){ 
        cin >> A[d];
        total += A[d];
    }
    int max_h = sqrt(total);

   // cout <<"max:" << max_h << " " <<"total:"<< total  << endl;
    if(max_h > n){ 
        //cout <<"change:"<< n  << endl;
        max_h = n;
    }
    

    //sqrt(total) ~ 1段まで ピラミッドを構成してみる。
    for(int d = max_h; d > 0; d--){
        if(total == max_h*max_h||true ){
            for(int e = 0; e <= 2*d-2;e++){
                if( A[e]-piramidd(e+1,d)>0) tmp+= A[e]-piramidd(e+1,d);
                else tmp2 += (piramidd(e+1,d)- A[e]);
          //      cout << "A[e]:"<< A[e] << " | " << "pi(e,d)" << piramidd(e+1,d) << "  "  << A[e]-piramidd(e+1,d) << endl;
            }
        //    cout << "tmp2:" << tmp2 << endl;
        }else{
            //ゴミ捨て場に移す必要がある
            for(int e = 1; e <= 2*d-1;e++){
                if( A[e]-piramidd(e,d)>0) tmp+= A[e]-piramidd(e,d);
                cout << A[e]-piramidd(e,d) << endl;
            }
        }
        if(tmp2 > tmp){ tmp = tmp2;}

        if(min > tmp){
            min = tmp;
        }
        
        //cout << "test^^"<< endl;
    }
    cout << min << endl;


    return 0;
}
0