結果

問題 No.77 レンガのピラミッド
ユーザー uafr_csuafr_cs
提出日時 2015-06-08 20:10:21
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,102 bytes
コンパイル時間 2,466 ms
コンパイル使用メモリ 76,376 KB
実行使用メモリ 56,844 KB
最終ジャッジ日時 2023-09-20 19:56:29
合計ジャッジ時間 7,199 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
55,636 KB
testcase_01 AC 114 ms
55,836 KB
testcase_02 AC 114 ms
56,096 KB
testcase_03 AC 114 ms
56,844 KB
testcase_04 AC 116 ms
55,940 KB
testcase_05 AC 114 ms
55,744 KB
testcase_06 WA -
testcase_07 AC 117 ms
55,440 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 117 ms
55,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {
	
	public static final int MAX = 1000000;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		int[] arr = new int[N];
		for(int i = 0; i < N; i++){
			arr[i] = sc.nextInt();
		}
		
		final int sum = Arrays.stream(arr).sum();
		
		int diff = Integer.MAX_VALUE;
		for(int i = 1; i <= N; i += 2){
			final int needs = (i / 2 + 1) * (i / 2 + 1);
			//System.out.println(sum + " " + needs);
			
			if(needs > sum){
				break;
			}
			
			int over = 0, under = 0;
			
			for(int j = 0; j < N; j++){
				final int need_height = Math.max(0, (i / 2 + 1) - Math.abs((j + 1) - (i / 2 + 1)));
				//System.out.println(i + " " + j + " " + need_height);
			
				if(arr[j] < need_height){
					under += need_height - arr[j];
				}else if(arr[j] > need_height){
					over += arr[j] - need_height;
				}
			}
				
			diff = Math.min(diff,  Math.max(under, over));
		}
		
		System.out.println(diff);
	}
	
}
0