結果
| 問題 |
No.77 レンガのピラミッド
|
| コンテスト | |
| ユーザー |
data9824
|
| 提出日時 | 2015-06-04 00:42:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 889 bytes |
| コンパイル時間 | 457 ms |
| コンパイル使用メモリ | 63,376 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-06 14:04:59 |
| 合計ジャッジ時間 | 1,287 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 20 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int givenBlocks = accumulate(a.begin(), a.end(), 0);
int minMovement = numeric_limits<int>::max();
for (int height = 1;; ++height) {
int width = height * 2 - 1;
int blocks = 0;
int movement = 0;
for (int x = 0; x < max<int>(width, a.size()); ++x) {
int y;
if (x < height) {
y = x + 1;
} else if (x < width) {
y = 2 * height - x - 1;
} else {
y = 0;
}
blocks += y;
int current = ((size_t)x < a.size() ? a[x] : 0);
if (y < current) {
movement += current - y;
}
}
if (givenBlocks < blocks) {
break;
}
minMovement = min(minMovement, movement);
}
cout << minMovement << endl;
return 0;
}
data9824