結果
問題 | No.77 レンガのピラミッド |
ユーザー |
![]() |
提出日時 | 2017-10-01 10:48:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 601 bytes |
コンパイル時間 | 1,572 ms |
コンパイル使用メモリ | 166,232 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-15 21:31:23 |
合計ジャッジ時間 | 2,549 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> using namespace std; int n; int a[111]; // 1 // 4 // 9 // 16 // int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } const int sum = accumulate(a, a + n, 0); int ans = 1e9; for (int i = 1; i * i <= sum; i++) { int pre = 0; for (int j = 0; j < n; j++) { int need = (j < i ? j + 1 : i * 2 - j - 1); need = max(0, need); if (need < a[j]) { pre += a[j] - need; } } ans = min(ans, pre); } cout << ans << endl; return 0; }