結果

問題 No.77 レンガのピラミッド
ユーザー tsunabittsunabit
提出日時 2020-01-08 14:47:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 162 ms / 5,000 ms
コード長 1,039 bytes
コンパイル時間 4,189 ms
コンパイル使用メモリ 77,268 KB
実行使用メモリ 54,564 KB
最終ジャッジ日時 2024-05-02 12:45:06
合計ジャッジ時間 8,540 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 138 ms
54,456 KB
testcase_01 AC 147 ms
54,068 KB
testcase_02 AC 146 ms
54,172 KB
testcase_03 AC 150 ms
53,852 KB
testcase_04 AC 148 ms
53,880 KB
testcase_05 AC 150 ms
54,196 KB
testcase_06 AC 162 ms
54,168 KB
testcase_07 AC 149 ms
53,964 KB
testcase_08 AC 157 ms
54,268 KB
testcase_09 AC 149 ms
54,272 KB
testcase_10 AC 142 ms
54,184 KB
testcase_11 AC 143 ms
54,268 KB
testcase_12 AC 150 ms
54,080 KB
testcase_13 AC 156 ms
54,252 KB
testcase_14 AC 161 ms
54,564 KB
testcase_15 AC 152 ms
54,172 KB
testcase_16 AC 150 ms
53,848 KB
testcase_17 AC 141 ms
54,092 KB
testcase_18 AC 154 ms
53,748 KB
testcase_19 AC 146 ms
54,184 KB
testcase_20 AC 142 ms
54,144 KB
testcase_21 AC 148 ms
54,076 KB
testcase_22 AC 147 ms
53,996 KB
testcase_23 AC 145 ms
54,308 KB
testcase_24 AC 138 ms
53,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;

public class No77 {
//	private static Set<String> set = new HashSet<String>();
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[200];
		Arrays.fill(a, 0);
		int total_ini = 0;
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			total_ini += a[i];
		}
		// ピラミッドの石の数から列数判定
		int c = (int)Math.sqrt(total_ini) * 2 - 1;
		// 配列にピラミッド生成
		int[] p = new int[200];
		Arrays.fill(p, 0);
		int ato = 0;
		for(int i = 0; i < c; i++) {
			if(i >= c/2+1) p[i] = p[i-1] - 1;
			else p[i] = i + 1;
			ato += p[i];
		}
		// 移動個数判定
		int ido = 0;
		// 移動した石をカウント
		for(int i = 0; i < p.length; i++) {
			if(a[i] == 0 && p[i] == 0) break;
			if(a[i] < p[i]) ido += p[i] - a[i];
		}
		// 捨てた石をカウント(初期値とピラミッドの石の差分をカウント)
		ido += total_ini - ato;	
		System.out.println(ido);
	}
}
0