結果
| 問題 |
No.77 レンガのピラミッド
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-11-26 14:26:55 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 129 ms / 5,000 ms |
| コード長 | 1,072 bytes |
| コンパイル時間 | 3,666 ms |
| コンパイル使用メモリ | 79,580 KB |
| 実行使用メモリ | 41,800 KB |
| 最終ジャッジ日時 | 2025-01-03 08:56:44 |
| 合計ジャッジ時間 | 7,697 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 20 |
ソースコード
import java.util.Scanner;
public class Main77 {
public static void main(String[] args) {
Main77 p = new Main77();
}
public Main77() {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[201];
for(int i=0;i<n;i++)
a[i] = sc.nextInt();
solve(n, a);
}
public void solve(int n, int[] a) {
int res = Integer.MAX_VALUE;
int[] sum = new int[a.length];
sum[0] = a[0];
for(int i=sum.length-2;i>=0;i--)
sum[i] += sum[i+1] + a[i];
for(int i=0;i<a.length/2;i++){
int cur = -1;
int e = 0;
int f = 0;
for(int j=0;j<i+1;j++){
if(a[j] - (j+1) > 0)
e+=a[j] - (j+1);
else
f-=(a[j] - (j+1));
}
for(int j=i+1;j<i*2+1;j++){
if(a[j] - (i*2+1-j) > 0)
e+=a[j] - (i*2+1-j);
else
f-=(a[j] - (i*2+1-j));
}
if(e>=f)
cur = e + sum[i*2+1];
else if(f>=e && f-e <= sum[i*2])
cur = e + sum[i*2+1];
if(cur>=0){
res = Math.min(res, cur);
}
}
System.out.println(res);
}
}