結果

問題 No.77 レンガのピラミッド
ユーザー tentententen
提出日時 2020-12-07 17:48:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 138 ms / 5,000 ms
コード長 1,191 bytes
コンパイル時間 2,136 ms
コンパイル使用メモリ 77,528 KB
実行使用メモリ 57,776 KB
最終ジャッジ日時 2023-10-17 16:35:25
合計ジャッジ時間 6,626 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
57,452 KB
testcase_01 AC 128 ms
57,500 KB
testcase_02 AC 131 ms
57,576 KB
testcase_03 AC 131 ms
57,528 KB
testcase_04 AC 130 ms
57,528 KB
testcase_05 AC 132 ms
57,440 KB
testcase_06 AC 138 ms
57,712 KB
testcase_07 AC 127 ms
57,244 KB
testcase_08 AC 137 ms
57,584 KB
testcase_09 AC 130 ms
57,668 KB
testcase_10 AC 130 ms
57,640 KB
testcase_11 AC 131 ms
57,536 KB
testcase_12 AC 136 ms
57,744 KB
testcase_13 AC 136 ms
57,604 KB
testcase_14 AC 138 ms
57,700 KB
testcase_15 AC 131 ms
57,604 KB
testcase_16 AC 128 ms
57,364 KB
testcase_17 AC 130 ms
57,472 KB
testcase_18 AC 134 ms
57,668 KB
testcase_19 AC 126 ms
57,296 KB
testcase_20 AC 130 ms
57,608 KB
testcase_21 AC 137 ms
57,636 KB
testcase_22 AC 128 ms
57,776 KB
testcase_23 AC 132 ms
55,632 KB
testcase_24 AC 128 ms
57,452 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[] arr = new int[1000];
        int total = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            total += arr[i];
        }
        int min = Integer.MAX_VALUE;
        for (int i = 1; ; i += 2) {
            int height = i / 2 + 1;
            if (height * height > total) {
                break;
            }
            int length = height * 2 - 1;
            int count = 0;
            int size = 1;
            int idx = 1;
            while (idx < arr.length) {
                if (arr[idx - 1] == 0 && size == 0) {
                    break;
                }
                count += Math.max(arr[idx - 1] - size, 0);
                if (idx >= height) {
                    size--;
                    if (size < 0) {
                        size = 0;
                    }
                } else {
                    size++;
                }
                idx++;
            }
            min = Math.min(min, count);
        }
        System.out.println(min);
    }
}
0