結果

問題 No.77 レンガのピラミッド
ユーザー kou6839kou6839
提出日時 2014-11-26 14:05:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 135 ms / 5,000 ms
コード長 966 bytes
コンパイル時間 2,122 ms
コンパイル使用メモリ 73,188 KB
実行使用メモリ 56,356 KB
最終ジャッジ日時 2023-09-01 22:10:51
合計ジャッジ時間 6,401 ms
ジャッジサーバーID
(参考情報)
judge13 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
56,176 KB
testcase_01 AC 121 ms
55,848 KB
testcase_02 AC 123 ms
56,100 KB
testcase_03 AC 122 ms
56,036 KB
testcase_04 AC 124 ms
55,584 KB
testcase_05 AC 121 ms
55,712 KB
testcase_06 AC 133 ms
55,720 KB
testcase_07 AC 121 ms
56,356 KB
testcase_08 AC 135 ms
55,704 KB
testcase_09 AC 126 ms
55,900 KB
testcase_10 AC 125 ms
55,820 KB
testcase_11 AC 124 ms
55,796 KB
testcase_12 AC 131 ms
55,844 KB
testcase_13 AC 132 ms
55,568 KB
testcase_14 AC 131 ms
55,368 KB
testcase_15 AC 126 ms
55,572 KB
testcase_16 AC 125 ms
55,448 KB
testcase_17 AC 124 ms
55,904 KB
testcase_18 AC 130 ms
55,580 KB
testcase_19 AC 122 ms
55,928 KB
testcase_20 AC 118 ms
56,232 KB
testcase_21 AC 127 ms
55,640 KB
testcase_22 AC 127 ms
55,664 KB
testcase_23 AC 128 ms
55,652 KB
testcase_24 AC 119 ms
55,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
 

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int ans=Integer.MAX_VALUE;
		int[] block = new int[101];
		int motokazu=0;
		for(int i=0;i<n;i++){
			int temp=sc.nextInt();
			motokazu+=temp;
			block[i]=temp;
		}
		for(int i=1;;i++){
			int[] pira = new int[1000];
			int kazu=0;
			for(int j=0;;){
				for(int k=1;k<=i;k++){
					kazu+=k;
					pira[j]=k;
					j++;
				}
				for(int l=i-1;l>0;l--){
					kazu+=l;
					pira[j]=l;
					j++;
				}
				break;
			}
			if(motokazu<kazu) break;;
			int dai=0;
			int syou=0;
			for(int j=0;j<101;j++){
				if(block[j]>pira[j]){
					dai+=block[j]-pira[j];
				}else if(block[j]<pira[j]){
					syou+=pira[j]-block[j];
				}
			}
			if(dai==syou){
				ans=Math.min(ans, dai);
			}
			if(dai>syou){
				ans=Math.min(ans, dai);
			}
		}
		System.out.println(ans);
	}
}			
	
0