結果

問題 No.77 レンガのピラミッド
ユーザー GoryudyumaGoryudyuma
提出日時 2017-03-20 21:03:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 133 ms / 5,000 ms
コード長 1,519 bytes
コンパイル時間 2,226 ms
コンパイル使用メモリ 72,056 KB
実行使用メモリ 56,568 KB
最終ジャッジ日時 2023-09-18 13:21:35
合計ジャッジ時間 6,979 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,984 KB
testcase_01 AC 125 ms
55,780 KB
testcase_02 AC 123 ms
55,708 KB
testcase_03 AC 123 ms
55,968 KB
testcase_04 AC 122 ms
56,048 KB
testcase_05 AC 120 ms
55,588 KB
testcase_06 AC 132 ms
56,016 KB
testcase_07 AC 120 ms
55,820 KB
testcase_08 AC 130 ms
56,024 KB
testcase_09 AC 124 ms
56,200 KB
testcase_10 AC 123 ms
55,596 KB
testcase_11 AC 125 ms
56,328 KB
testcase_12 AC 131 ms
56,568 KB
testcase_13 AC 131 ms
55,976 KB
testcase_14 AC 133 ms
56,012 KB
testcase_15 AC 132 ms
55,916 KB
testcase_16 AC 126 ms
55,980 KB
testcase_17 AC 123 ms
56,024 KB
testcase_18 AC 130 ms
56,216 KB
testcase_19 AC 122 ms
55,648 KB
testcase_20 AC 122 ms
55,464 KB
testcase_21 AC 127 ms
56,020 KB
testcase_22 AC 125 ms
55,808 KB
testcase_23 AC 127 ms
56,068 KB
testcase_24 AC 122 ms
55,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        int N = sc.nextInt();
                        int[] A = new int[N];
                        int sum = 0;
                        for (int i = 0; i < N; i++) {
                                A[i] = sc.nextInt();
                                sum += A[i];
                        }
                        int ans = 1 << 29;
                        for (int i = 1; i * i <= sum; i++) {
                                int count = 0;
                                int stock = 0;
                                for (int j = 0; j < N; j++) {
                                        int x;
                                        if (j >= i) {
                                                x = i * 2 - j - 1;
                                        } else {
                                                x = j + 1;
                                        }
                                        if (x <= 0) {
                                                x = 0;
                                        }
                                        count += Math.abs(A[j] - x);
                                        stock += A[j] - x;
                                }
                                ans = Math.min((count + stock) / 2, ans);
                        }
                        System.out.println(ans);
                }
        }
}
0