結果

問題 No.77 レンガのピラミッド
ユーザー tsunabittsunabit
提出日時 2020-01-08 14:46:15
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,077 bytes
コンパイル時間 3,826 ms
コンパイル使用メモリ 79,184 KB
実行使用メモリ 42,292 KB
最終ジャッジ日時 2024-05-02 12:44:52
合計ジャッジ時間 8,844 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
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 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
		System.out.println("colum = " + c);
		// 配列にピラミッド生成
		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