結果

問題 No.77 レンガのピラミッド
ユーザー jp_stejp_ste
提出日時 2016-02-29 02:13:47
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,181 bytes
コンパイル時間 2,559 ms
コンパイル使用メモリ 76,732 KB
実行使用メモリ 57,720 KB
最終ジャッジ日時 2023-10-24 19:03:46
合計ジャッジ時間 6,989 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
57,308 KB
testcase_01 AC 119 ms
57,080 KB
testcase_02 RE -
testcase_03 AC 120 ms
57,408 KB
testcase_04 AC 119 ms
57,476 KB
testcase_05 AC 109 ms
56,076 KB
testcase_06 AC 129 ms
57,508 KB
testcase_07 RE -
testcase_08 AC 136 ms
57,456 KB
testcase_09 AC 133 ms
57,608 KB
testcase_10 AC 122 ms
56,080 KB
testcase_11 AC 122 ms
57,456 KB
testcase_12 AC 133 ms
57,628 KB
testcase_13 AC 130 ms
57,324 KB
testcase_14 AC 131 ms
57,512 KB
testcase_15 AC 121 ms
57,180 KB
testcase_16 AC 121 ms
57,452 KB
testcase_17 AC 110 ms
56,112 KB
testcase_18 AC 131 ms
57,720 KB
testcase_19 AC 120 ms
57,424 KB
testcase_20 AC 119 ms
57,472 KB
testcase_21 AC 115 ms
56,176 KB
testcase_22 AC 123 ms
57,708 KB
testcase_23 AC 124 ms
57,356 KB
testcase_24 AC 120 ms
57,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Scanner;

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