結果
| 問題 |
No.77 レンガのピラミッド
|
| コンテスト | |
| ユーザー |
Tatsu_mr
|
| 提出日時 | 2024-10-13 17:55:37 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,192 bytes |
| コンパイル時間 | 3,037 ms |
| コンパイル使用メモリ | 245,804 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 17:55:41 |
| 合計ジャッジ時間 | 3,876 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
#define For(i, a, b) for(long long i = a; i < b; i++)
#define rep(i, n) For(i, 0, n)
#define rFor(i, a, b) for(long long i = a; i >= b; i--)
#define ALL(v) (v).begin(), (v).end()
#define rALL(v) (v).rbegin(), (v).rend()
using namespace std;
using lint = long long;
using ld = long double;
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) {
cin >> a[i];
}
int sum = accumulate(ALL(a), 0);
int ans = 2000000000;
for (int i = 1; ; i += 2) {
int h = (i + 1) / 2;
if (h * h > sum) {
break;
}
vector<int> len(i);
for (int j = 0; j < h; j++) {
len[j] = len[i - 1 - j] = j + 1;
}
int more = 0, less = 0;
rep(j, max(i, n)) {
if (j < n && j < i) {
if (a[j] > len[j]) {
more += a[j] - len[j];
} else {
less += len[j] - a[j];
}
} else if (j < n) {
more += a[j];
} else {
less += len[j];
}
}
ans = min(ans, max(more, less));
}
cout << ans << endl;
}
Tatsu_mr