結果

問題 No.77 レンガのピラミッド
ユーザー jp_stejp_ste
提出日時 2016-02-29 02:05:50
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,154 bytes
コンパイル時間 3,268 ms
コンパイル使用メモリ 74,896 KB
実行使用メモリ 57,768 KB
最終ジャッジ日時 2023-10-24 19:02:48
合計ジャッジ時間 7,802 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
57,552 KB
testcase_01 AC 135 ms
57,332 KB
testcase_02 AC 132 ms
57,600 KB
testcase_03 AC 129 ms
57,456 KB
testcase_04 AC 127 ms
57,300 KB
testcase_05 AC 130 ms
57,372 KB
testcase_06 RE -
testcase_07 AC 129 ms
57,620 KB
testcase_08 RE -
testcase_09 AC 128 ms
57,336 KB
testcase_10 AC 119 ms
56,264 KB
testcase_11 AC 130 ms
57,356 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 131 ms
57,200 KB
testcase_16 AC 127 ms
57,384 KB
testcase_17 AC 128 ms
57,228 KB
testcase_18 RE -
testcase_19 AC 129 ms
57,564 KB
testcase_20 AC 129 ms
57,232 KB
testcase_21 AC 132 ms
57,608 KB
testcase_22 AC 133 ms
55,568 KB
testcase_23 AC 135 ms
57,564 KB
testcase_24 AC 126 ms
57,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner scan = new Scanner(System.in)) {
            int N = scan.nextInt();
            int list[] = new int[101];
            int ansList[] = new int[101];
            int sum = 0;
            for(int i=0; i<N; i++) {
                list[i] = scan.nextInt();
                sum += list[i];
            }
            
            int sqrtSum = (int)Math.sqrt(sum);
            sum = sqrtSum * sqrtSum;
            
            int mid = sum/2;
            int index = 0;
            int value = 1;
            while(sum > 0) {
                ansList[index] = value;
                sum -= value;
                if(sum < mid) {
                    value--;
                } else {
                    value++;
                }
                index++;
            }
            
            int ans = 0;
            for(int i=0; i<101; i++) {
                int diff = list[i] - ansList[i];
                if(diff > 0) {
                    ans += diff;
                }
            }
            System.out.println(ans);
        }
    }
}
0