結果
| 問題 |
No.77 レンガのピラミッド
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-01-25 17:23:46 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 478 bytes |
| コンパイル時間 | 863 ms |
| コンパイル使用メモリ | 104,960 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-12 06:35:06 |
| 合計ジャッジ時間 | 1,778 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 20 |
ソースコード
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
auto n = readln.chomp.to!size_t;
auto ai = readln.split.to!(int[]);
auto sumA = ai.sum;
auto r = int.max;
for (auto p = 1; (p + 1) ^^ 2 / 4 <= sumA; p += 2) {
auto s = 0;
foreach (i, a; ai) {
if (i >= p) {
s += a;
} else {
auto b = i < (p + 1) / 2 ? i + 1 : p - i;
if (a > b) s += a - b;
}
}
r = min(r, s);
}
writeln(r);
}