結果

問題 No.77 レンガのピラミッド
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-10-22 21:37:04
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,234 bytes
コンパイル時間 503 ms
コンパイル使用メモリ 62,204 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-02 22:36:48
合計ジャッジ時間 1,290 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1e9;

int n, a[110];
int main(void){
	cin >> n;
	int sum = 0;
	rep(i, n){
		cin >> a[i];
		sum += a[i];
	}

	int ans = INF;
	for (int i = 1; i <= n; i += 2)//何列ピラミッドにするか
	{
		int tarinai = 0, amari = 0;
		int aim = 0;
		//左側 + 真ん中
		for (int l = 0; l < i / 2 + 1; ++l)
		{
			aim++;
			if(a[l] < aim){
				tarinai += aim - a[l];
			}else{
				amari += a[l] - aim;
			}
		}

		aim = 0;
		//右側
		for (int r = i - 1; r >= i / 2 + 1; --r)
		{
			aim++;
			if(a[r] < aim){
				tarinai += aim - a[r];
			}else{
				amari += a[r] - aim;
			}
		}

		//使わない列
		for (int j = i; j < n; ++j)
		{
			amari += a[j];
		}


		if(amari >= tarinai){
			//足りないところに余りから追加するのに、足りない分だけのコスト tarinai
			//余りを足りないところに追加して、残った分を捨て置き場に移動するコスト amari - tariani
			ans = min(ans, tarinai + amari - tarinai);
			// ans = min(ans, amari);
		}
	}
	printf("%d\n", ans);
	return 0;
}
0