結果

問題 No.77 レンガのピラミッド
ユーザー nanophoto12nanophoto12
提出日時 2015-12-27 23:26:02
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,785 bytes
コンパイル時間 574 ms
コンパイル使用メモリ 72,936 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 11:24:40
合計ジャッジ時間 1,450 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

#define FOR(x,y) for(int x = 0;x < y;x++)
#define LLI long long int

template<int um> class UF {
public:
    vector<int> par,rank,cnt;
    UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
    void reinit() {FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
    int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
    int count(int x) { return cnt[operator[](x)];}
    int operator()(int x,int y) {
        if((x=operator[](x))==(y=operator[](y))) return x;
        cnt[y]=cnt[x]=cnt[x]+cnt[y];
        if(rank[x]>rank[y]) return par[x]=y;
        rank[x]+=rank[x]==rank[y]; return par[y]=x;
    }
};

int main() {
    int n;
    cin >> n;
    vector<int> data(n);
    int sum = 0;
    FOR(i, n)
    {
        cin >> data[i];
        sum += data[i];
    }
    int maxSize = sqrt(sum) + 1;
    //cout << "maxSize:" << maxSize << endl;
    int minOperation = 1000000000;
    for(int i = 1; i < maxSize*2;i += 2)
    {
        if((i/2) * (i/2) > sum)
        {
            continue;
        }
        //cout << "i:" << i << endl;
        int middleIndex = i / 2;
        int count = 0;
        for(int x = 0;x < i;x++)
        {
            int height = middleIndex - abs(middleIndex-x) + 1;
            //cout << "height:" << height << endl;
            if(x < n)
            {
                count += abs(height - data[x]);
            }
            else
            {
                count += height;
            }
        }
        for(int x = i;x < n;x++)
        {
            count += data[x];
        }
        minOperation = min(minOperation, count);
    }
    cout << minOperation << endl;
    return 0;
}
0