結果

問題 No.77 レンガのピラミッド
ユーザー hotpepsihotpepsi
提出日時 2015-08-13 02:19:26
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 897 bytes
コンパイル時間 253 ms
コンパイル使用メモリ 52,020 KB
最終ジャッジ日時 2024-04-27 02:09:20
合計ジャッジ時間 662 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:16:26: error: ‘sqrt’ was not declared in this scope
   16 |         int max_n = (int)sqrt(sum);
      |                          ^~~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <numeric>

using namespace std;

int main(int argc, char *argv[])
{
	int N, A[201] = {};
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	int ans = 1 << 30;
	int sum = accumulate(A, A + N, 0);
	int max_n = (int)sqrt(sum);
	for (int len = 1; len <= max_n; ++len) {
		int in = 0;
		int out = accumulate(A + len * 2 - 1, A + 201, 0);
		for (int j = 0; j < len - 1; ++j) {
			int a = A[j], b = A[len * 2 - 2 - j];
			int d = j + 1 - a;
			if (d > 0) {
				in += d;
			} else {
				out -= d;
			}
			d = j + 1 - b;
			if (d > 0) {
				in += d;
			} else {
				out -= d;
			}
		}
		int d = len - A[len - 1];
		if (d > 0) {
			in += d;
		} else {
			out -= d;
		}
		if (len == 50) {
			int i = 0;
			++i;
		}
		if (len == 51) {
			int i = 0;
			++i;
		}
		in -= min(in, out);
		ans = min(ans, in + out);
	}
	cout << ans << endl;
	return 0;
}
0