結果

問題 No.77 レンガのピラミッド
ユーザー 158b158b
提出日時 2015-06-07 21:08:56
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,010 bytes
コンパイル時間 555 ms
コンパイル使用メモリ 70,692 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 19:38:59
合計ジャッジ時間 2,849 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
using namespace std;

#define long __int64
//#define __int64 long long
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vecy[4] = {0,-1,0,1};
const int Vecx[4] = {1,0,-1,0};

int main(){
	int n;
	int from[100] = {0};
	int to[100];//1,4,9,16...
	int sum = 0;
	int weight;
	int check;
	int plus = 0;
	int minus = 0;
	
	cin >> n;
	rep(i,n){
		cin >> from[i];
		sum += from[i];
	}
	
	check = 4;
	weight = 1;
	while(sum >= check){
		weight += 2;
		check += weight + 2;
	}
	
	for(int i=0; i<=weight/2; i++){
		to[i] = i + 1;
		to[weight-i-1] = i + 1;
	}
	
	for(int i=0; i<weight; i++){
		//cout << to[i] << " - " << from[i] << " = " << to[i] - from[i] << endl;
		if(from[i] < to[i]){
			plus += to[i] - from[i];
		}else if(from[i] > to[i]){
			minus += from[i] - to[i];
		}
	}
	
	cout << max(plus, minus) << endl;
	
    return 0;
}
0