結果

問題 No.77 レンガのピラミッド
ユーザー GrenacheGrenache
提出日時 2015-11-06 18:33:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 135 ms / 5,000 ms
コード長 801 bytes
コンパイル時間 3,661 ms
コンパイル使用メモリ 72,028 KB
実行使用メモリ 57,760 KB
最終ジャッジ日時 2023-10-11 14:23:44
合計ジャッジ時間 7,962 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,500 KB
testcase_01 AC 125 ms
55,772 KB
testcase_02 AC 126 ms
55,932 KB
testcase_03 AC 126 ms
55,772 KB
testcase_04 AC 124 ms
56,032 KB
testcase_05 AC 125 ms
56,004 KB
testcase_06 AC 135 ms
55,708 KB
testcase_07 AC 126 ms
55,928 KB
testcase_08 AC 135 ms
55,592 KB
testcase_09 AC 127 ms
56,172 KB
testcase_10 AC 127 ms
55,816 KB
testcase_11 AC 129 ms
54,304 KB
testcase_12 AC 135 ms
56,012 KB
testcase_13 AC 135 ms
55,964 KB
testcase_14 AC 134 ms
55,792 KB
testcase_15 AC 129 ms
55,704 KB
testcase_16 AC 129 ms
55,668 KB
testcase_17 AC 128 ms
55,632 KB
testcase_18 AC 133 ms
57,760 KB
testcase_19 AC 128 ms
55,760 KB
testcase_20 AC 127 ms
55,792 KB
testcase_21 AC 132 ms
55,884 KB
testcase_22 AC 131 ms
56,052 KB
testcase_23 AC 132 ms
55,768 KB
testcase_24 AC 127 ms
55,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder77 {

    public static void main(String[] args) {
        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 nn = (int)Math.sqrt(sum);
        int p = 0;
        int m = 0;
        for (int i = 0; i < n; i++) {
        	int tmp;
        	if (i < nn) {
        		tmp = i + 1;
        	} else {
        		tmp = Math.max(0, nn - (i - nn + 1));
        	}
        	
        	if (a[i] > tmp) {
        		p += a[i] - tmp;
        	} else {
        		m += tmp - a[i];
        	}
        }

        System.out.println(m + Math.max(0, p - m));

        sc.close();
    }
}
0