結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,628 KB
testcase_01 AC 122 ms
55,836 KB
testcase_02 AC 122 ms
55,704 KB
testcase_03 AC 123 ms
55,912 KB
testcase_04 AC 127 ms
55,580 KB
testcase_05 AC 125 ms
56,224 KB
testcase_06 WA -
testcase_07 AC 122 ms
55,964 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 121 ms
56,052 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{
						count++;
					}
				}
			}
			
			diff = Math.min(diff, count);
		}
		
		System.out.println(diff);
	}
	
}
0