結果
| 問題 | No.77 レンガのピラミッド |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-01-29 17:50:57 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,075 bytes |
| 記録 | |
| コンパイル時間 | 3,558 ms |
| コンパイル使用メモリ | 337,392 KB |
| 実行使用メモリ | 7,972 KB |
| 最終ジャッジ日時 | 2026-01-29 17:51:03 |
| 合計ジャッジ時間 | 4,653 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 19 WA * 1 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
vector<int> pyramid(int p) {
vector<int> t;
for (int i = 1; i <= p; i++) t.push_back(i);
for (int i = p - 1; i >= 1; i--) t.push_back(i);
return t;
}
int main() {
int n;
cin >> n;
int tot = 0;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
tot += a[i];
}
int ans = 1000000000;
for (int j = 2; j * j <= tot; j++) {
vector<int> p = pyramid(j);
int excess = 0;
int shor = 0;
for (int i = 0; i < max((int)p.size(), (int)a.size()); i++) {
if (i < a.size() && i < p.size()) {
if (a[i] > p[i]) {
excess += a[i] - p[i];
} else if (a[i] < p[i]) {
shor += p[i] - a[i];
}
} else if (i >= a.size()) {
shor += p[i];
} else if (i >= p.size()) {
excess += a[i];
}
}
ans = min(ans, max(excess, shor));
}
cout << ans << endl;
return 0;
}