結果

問題 No.77 レンガのピラミッド
ユーザー uafr_csuafr_cs
提出日時 2015-06-08 20:05:26
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,415 bytes
コンパイル時間 2,103 ms
コンパイル使用メモリ 75,720 KB
実行使用メモリ 57,360 KB
最終ジャッジ日時 2023-09-20 19:56:12
合計ジャッジ時間 6,477 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,896 KB
testcase_01 AC 124 ms
55,896 KB
testcase_02 AC 124 ms
55,916 KB
testcase_03 AC 124 ms
55,700 KB
testcase_04 AC 124 ms
55,748 KB
testcase_05 AC 123 ms
55,472 KB
testcase_06 WA -
testcase_07 AC 126 ms
56,040 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 120 ms
55,600 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 drop = 0, count = 0;
			
			for(int j = 0; j < i; j++){
				final int need_height = (i / 2 + 1) - Math.abs((j + 1) - (i / 2 + 1));
				//System.out.println(i + " " + need_height + " " +arr[j] + " " + drop + " " + count);
				
				
				for(int d = Math.abs(arr[j] - need_height); d > 0; d--){
					if(arr[j] > need_height){
						if(drop >= 0){
							count++;
						}
						drop++;
					}else if(arr[j] < need_height){
						if(drop <= 0){
							count++;
						}
						drop--;
					}
				}
			}
			
			for(int j = i; j < N; j++){
				for(int k = 0; k < arr[j]; k++){
					if(drop > 0){
						drop--;
					}else if (drop < 0){
						drop++;
					}else{
						count++;
					}
				}
			}
			
			diff = Math.min(diff, count);
		}
		
		System.out.println(diff);
	}
	
}
0