結果
問題 | No.77 レンガのピラミッド |
ユーザー |
![]() |
提出日時 | 2014-11-26 01:20:38 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 735 bytes |
コンパイル時間 | 696 ms |
コンパイル使用メモリ | 104,776 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-12 01:40:08 |
合計ジャッジ時間 | 1,568 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 20 |
ソースコード
import std.stdio, std.conv, std.math, std.string, std.range, std.array, std.algorithm; void main(){ auto N = readln().strip().to!int(); int[] A = readln().strip().split().map!(to!int)().array(); A.length = 5050; int ans = int.max; int i; for(;;) { ++ i; int neg, pos; foreach(int j; 0 .. i) { int dif = A[j] - (j+1); if(dif >= 0) pos += dif; else neg += -dif; if(j != i-1) { int difr = A[2*i-j-2] - (j+1); if(difr >= 0) pos += difr; else neg += -difr; } } foreach(int j; 2*i-1 .. N) { pos += A[j]; } if(neg > pos) break; ans = min(ans, pos); } writeln(ans); }