結果

問題 No.77 レンガのピラミッド
ユーザー kongarishisyamokongarishisyamo
提出日時 2016-02-29 02:40:43
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 728 bytes
コンパイル時間 444 ms
コンパイル使用メモリ 56,476 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 19:05:29
合計ジャッジ時間 1,330 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>

using namespace std;

#define NMAX 100

int main(){

	int N;
	int A[NMAX+1]={0};
	int sum[NMAX*2+1]={0};
	int suma=0;
	int ans=-1;
	int locd,loca;

	cin>>N;

	for(int i=1;i<=200;i+=2){
		int c=1;
		for(int j=0;j<i;j++){
			sum[i]+=c;
			if(i/2+1>j+1) c++;
			else c--;
		}
	}
	
	for(int i=1;i<=N;i++){
		cin>>A[i];
		suma+=A[i];
	}

	for(int i=1;;i+=2){
		if(sum[i]>suma) break;
		locd=0;
		loca=0;
		int c=1;
		for(int j=1;j<=i;j++){
			if(c>A[j]) loca+=c-A[j];
			else if(c<A[j]) locd+=A[j]-c;
			if(i/2+1>j) c++;
			else c--;
		}
		for(int j=i+1;j<=N;j++){
			locd+=A[j];
		}

		/*cout<<i<<","<<loca<<","<<locd<<endl;*/

		if(loca>locd) continue;
		if(ans==-1||locd<ans) ans=locd;
	}

	cout<<ans<<endl;

}
0