結果
問題 | No.77 レンガのピラミッド |
ユーザー |
|
提出日時 | 2016-08-29 15:40:28 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 765 bytes |
コンパイル時間 | 1,556 ms |
コンパイル使用メモリ | 154,696 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-12 03:48:50 |
合計ジャッジ時間 | 2,329 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 20 |
ソースコード
import std.algorithm, std.array, std.container, std.range; import std.string, std.conv, std.math, std.random; import std.stdio, std.typecons; void main() { auto n = readln.chomp.to!int; auto ai = readln.split.map!(to!int); auto min = int.max; auto sum = ai.sum; for (auto m = 1; m * m <= sum; ++m) { auto b = ai .zip(iota(n)) .map!(a => a[0] - blocks(m, a[1])) .filter!(a => a < 0) .sum * (-1); if (ai.length < m * 2 - 1) { auto c = (m * 2 - 1) - ai.length; b += c * (c + 1) / 2; } auto r = sum - m * m + b; if (r < min) min = r; } writeln(min); } int blocks(int m, int i) { if (i < m) return i + 1; else if (i >= m && i < m * 2 - 1) return m * 2 - i - 1; else return 0; }