結果

問題 No.77 レンガのピラミッド
ユーザー nak3
提出日時 2017-04-23 20:32:54
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 953 bytes
コンパイル時間 1,505 ms
コンパイル使用メモリ 160,536 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-22 10:06:10
合計ジャッジ時間 2,177 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 5 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


int main()
{
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll sum = accumulate(a, a+n, 0);
	int ret = 0;


	int tmp;
	for (int i = 1; i < 20; i++) {
		tmp = i*i;
		if (tmp>sum) {
			tmp = (i-1)*(i-1);
			break;
		}
	}

	int leng = sqrt(tmp);
	bool minus = false;
	if ((leng+leng-1)<n) {
		minus = true;
	}

//	cout << leng << "\n";
	int expect = 0;
	int stk = 0;
	for (int i = 0; i < n; i++) {
		if (leng<(i+1)) {
			expect--;
		} else {
			expect++;
		}
//		cout << "d_: " << expect << " " << a[i] << endl;
		if (a[i]==expect) {
			continue;
		} else {
			if (minus) {
				if (i<leng+leng-1) {
//					cout << ret << "\n";
					ret += abs((a[i]-expect));
				}
			} else {
				int tt = a[i]-expect;
				if (tt>0) {
					ret += tt;
				}
			}

		}
	}
	cout << ret << endl;

}
0