結果

問題 No.77 レンガのピラミッド
ユーザー kou6839kou6839
提出日時 2014-11-26 14:02:55
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 961 bytes
コンパイル時間 2,046 ms
コンパイル使用メモリ 74,088 KB
実行使用メモリ 58,412 KB
最終ジャッジ日時 2023-09-01 22:10:37
合計ジャッジ時間 6,389 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,812 KB
testcase_01 AC 123 ms
55,540 KB
testcase_02 AC 123 ms
55,624 KB
testcase_03 AC 124 ms
55,896 KB
testcase_04 AC 125 ms
56,036 KB
testcase_05 AC 125 ms
55,932 KB
testcase_06 RE -
testcase_07 AC 123 ms
55,380 KB
testcase_08 RE -
testcase_09 AC 126 ms
55,716 KB
testcase_10 AC 125 ms
56,088 KB
testcase_11 AC 127 ms
56,132 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 124 ms
55,380 KB
testcase_16 AC 124 ms
55,896 KB
testcase_17 AC 121 ms
55,704 KB
testcase_18 RE -
testcase_19 AC 123 ms
55,844 KB
testcase_20 AC 124 ms
55,924 KB
testcase_21 AC 129 ms
55,804 KB
testcase_22 AC 131 ms
55,632 KB
testcase_23 AC 130 ms
55,844 KB
testcase_24 AC 123 ms
55,660 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[101];
			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