結果

問題 No.77 レンガのピラミッド
ユーザー nksk38nksk38
提出日時 2017-07-22 17:14:43
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,296 bytes
コンパイル時間 687 ms
コンパイル使用メモリ 79,780 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 15:55:39
合計ジャッジ時間 1,622 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, string> pls;

int A[110],sum;

int main()
{
	int N;  cin >> N;
	int ans = (int)1e6;
	int sum_temp = 0;

	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sum += A[i];
	}

	sum_temp = sum;
	for (int i = 0; i < N; i++) {  
		int num = 0,stk = 0;
		sum = sum_temp;
		if (A[i] - (i + 1) > 0)
			num += A[i] - (i + 1);
		else
			stk += abs(A[i] - (i + 1));
		sum -= A[i];
		for (int j = 0; j < i; j++) {
			if (A[j] - (j + 1) > 0)
				num += A[j] - (j + 1);
			else
				stk += abs(A[j] - (j + 1));
			sum -= A[j];
		}
		int k = 0;
		for (int j = i+1; j < N; j++) {
			if (A[j] - (i-k) > 0)
				num += A[j] - (i-k);
			else
				stk += abs(A[j] - (i-k));

			sum -= A[j];
			k++;
			if (k >= i)break;
		}

		num += sum;
		if (N / 2 + N % 2 < i + 1) {
			if (num < ((i - 1)*i / 2)+stk)
				continue;
		}
		if (num < 0)continue;
		else ans = min(num, ans);
	}
	cout << ans << endl;
	return	0;
}
0