結果

問題 No.77 レンガのピラミッド
ユーザー scachescache
提出日時 2014-11-26 14:26:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 139 ms / 5,000 ms
コード長 1,072 bytes
コンパイル時間 3,652 ms
コンパイル使用メモリ 79,252 KB
実行使用メモリ 55,920 KB
最終ジャッジ日時 2023-09-01 22:11:36
合計ジャッジ時間 8,121 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,644 KB
testcase_01 AC 126 ms
55,524 KB
testcase_02 AC 126 ms
55,528 KB
testcase_03 AC 127 ms
55,456 KB
testcase_04 AC 126 ms
55,384 KB
testcase_05 AC 127 ms
55,684 KB
testcase_06 AC 139 ms
55,840 KB
testcase_07 AC 128 ms
55,372 KB
testcase_08 AC 135 ms
55,912 KB
testcase_09 AC 127 ms
55,612 KB
testcase_10 AC 126 ms
55,644 KB
testcase_11 AC 129 ms
55,444 KB
testcase_12 AC 135 ms
55,568 KB
testcase_13 AC 134 ms
55,580 KB
testcase_14 AC 135 ms
55,604 KB
testcase_15 AC 130 ms
55,716 KB
testcase_16 AC 128 ms
55,832 KB
testcase_17 AC 128 ms
55,836 KB
testcase_18 AC 135 ms
54,024 KB
testcase_19 AC 126 ms
55,604 KB
testcase_20 AC 127 ms
55,728 KB
testcase_21 AC 132 ms
55,692 KB
testcase_22 AC 126 ms
55,320 KB
testcase_23 AC 131 ms
55,464 KB
testcase_24 AC 126 ms
55,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


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);
		
	}

}
0