結果

問題 No.77 レンガのピラミッド
ユーザー fura
提出日時 2020-04-15 22:54:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 606 bytes
コンパイル時間 2,003 ms
コンパイル使用メモリ 195,588 KB
最終ジャッジ日時 2025-01-09 19:21:24
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:22:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |         int n; scanf("%d",&n);
      |                ~~~~~^~~~~~~~~
main.cpp:24:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |         rep(i,n) scanf("%d",&a[i]);
      |                  ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int INF=1<<29;

int f(vector<int> a,vector<int> b){
	while(a.size()<b.size()) a.emplace_back(0);
	while(b.size()<a.size()) b.emplace_back(0);

	int n=a.size(),d1=0,d2=0;
	rep(i,n){
		if(a[i]>=b[i]) d1+=a[i]-b[i];
		else           d2+=b[i]-a[i];
	}
	return d1<d2?INF:d1;
}

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	int ans=INF;
	for(int r=1;r<=1000;r+=2){
		vector<int> b(r);
		rep(i,r) b[i]=min(i+1,r-i);
		ans=min(ans,f(a,b));
	}
	printf("%d\n",ans);

	return 0;
}
0