結果

問題 No.77 レンガのピラミッド
ユーザー htensaihtensai
提出日時 2020-02-05 14:59:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 136 ms / 5,000 ms
コード長 921 bytes
コンパイル時間 4,314 ms
コンパイル使用メモリ 74,100 KB
実行使用メモリ 57,788 KB
最終ジャッジ日時 2023-10-23 19:55:08
合計ジャッジ時間 7,650 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
57,508 KB
testcase_01 AC 126 ms
57,632 KB
testcase_02 AC 124 ms
57,488 KB
testcase_03 AC 127 ms
57,484 KB
testcase_04 AC 124 ms
57,652 KB
testcase_05 AC 123 ms
57,456 KB
testcase_06 AC 136 ms
57,720 KB
testcase_07 AC 124 ms
57,512 KB
testcase_08 AC 133 ms
57,692 KB
testcase_09 AC 124 ms
57,532 KB
testcase_10 AC 131 ms
57,652 KB
testcase_11 AC 129 ms
57,656 KB
testcase_12 AC 132 ms
57,596 KB
testcase_13 AC 130 ms
57,732 KB
testcase_14 AC 135 ms
57,712 KB
testcase_15 AC 128 ms
57,688 KB
testcase_16 AC 127 ms
57,636 KB
testcase_17 AC 129 ms
57,656 KB
testcase_18 AC 132 ms
57,492 KB
testcase_19 AC 128 ms
57,452 KB
testcase_20 AC 117 ms
56,248 KB
testcase_21 AC 135 ms
57,656 KB
testcase_22 AC 129 ms
57,572 KB
testcase_23 AC 130 ms
57,788 KB
testcase_24 AC 125 ms
57,596 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[n];
        int total = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            total += arr[i];
        }
        int max = (int)(Math.sqrt(total));
        int min = Integer.MAX_VALUE;
        for (int i = 1; i <= max; i++) {
            int count = 0;
            int sum = 0;
            for (int j = 0; j < n; j++) {
                if (j < i) {
                    count++;
                } else {
                    count--;
                    if (count < 0) {
                        count = 0;
                    }
                }
                sum += Math.max(0, arr[j] - count);
            }
            min = Math.min(sum, min);
        }
        System.out.println(min);
    }
}
0