結果

問題 No.77 レンガのピラミッド
ユーザー jp_stejp_ste
提出日時 2016-02-29 02:19:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 140 ms / 5,000 ms
コード長 1,625 bytes
コンパイル時間 2,357 ms
コンパイル使用メモリ 86,036 KB
実行使用メモリ 57,644 KB
最終ジャッジ日時 2023-10-24 19:03:53
合計ジャッジ時間 5,955 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
57,332 KB
testcase_01 AC 119 ms
57,156 KB
testcase_02 AC 124 ms
57,204 KB
testcase_03 AC 120 ms
57,408 KB
testcase_04 AC 110 ms
56,068 KB
testcase_05 AC 118 ms
57,336 KB
testcase_06 AC 140 ms
57,232 KB
testcase_07 AC 118 ms
56,964 KB
testcase_08 AC 128 ms
57,300 KB
testcase_09 AC 124 ms
57,420 KB
testcase_10 AC 128 ms
57,536 KB
testcase_11 AC 122 ms
57,460 KB
testcase_12 AC 135 ms
57,556 KB
testcase_13 AC 134 ms
57,644 KB
testcase_14 AC 126 ms
57,172 KB
testcase_15 AC 121 ms
57,328 KB
testcase_16 AC 121 ms
57,212 KB
testcase_17 AC 112 ms
56,152 KB
testcase_18 AC 128 ms
57,440 KB
testcase_19 AC 124 ms
57,376 KB
testcase_20 AC 110 ms
56,124 KB
testcase_21 AC 128 ms
57,540 KB
testcase_22 AC 124 ms
57,440 KB
testcase_23 AC 126 ms
57,472 KB
testcase_24 AC 121 ms
57,380 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++;
                }
            }
            
            if(list.size() > ansList.size()) {
                int num = list.size() - ansList.size();
                for(int i=0; i<num; i++) {
                    ansList.add(0);
                }
            
            } else if(list.size() < ansList.size()) {
                int num = ansList.size() - list.size();
                for(int i=0; i<num; i++) {
                    list.add(0);
                }
            }
            
            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