結果

問題 No.77 レンガのピラミッド
ユーザー ikdikd
提出日時 2016-10-07 18:47:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 564 bytes
コンパイル時間 515 ms
コンパイル使用メモリ 68,236 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 14:59:08
合計ジャッジ時間 1,339 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include<algorithm>
using namespace std;

int main() {
	int N;
	cin>> N;
	int A[N];
	for(int i=0; i<N; i++) cin>> A[i];
	
	int sum=0;
	for(int i=0; i<N; i++) sum+=A[i];
	int m=1, s=1;
	while(s+m+2<=sum){
		m+=2;
		s+=m;
	}
	
	int pira[m];
	for(int i=0; i<m; i++){
		if(i<N) pira[i]=A[i];
		else pira[i]=0;
	}
	int ans=0;
	for(int i=0; i<m/2; i++){
		if(i+1<pira[i]){
			ans+=pira[i]-(i+1);
		}
		if(i+1<pira[m-i-1]){
			ans+=pira[N-i-1]-(i+1);
		}
	}
	if(m/2+1<pira[m/2]) ans+=pira[m/2]-(m/2+1);
	
	cout<< ans+max(0, N-m)<< endl;
	
	return 0;
}
0