結果

問題 No.77 レンガのピラミッド
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-18 01:57:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 135 ms / 5,000 ms
コード長 803 bytes
コンパイル時間 1,848 ms
コンパイル使用メモリ 74,612 KB
実行使用メモリ 41,784 KB
最終ジャッジ日時 2024-05-04 15:17:26
合計ジャッジ時間 5,884 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
41,440 KB
testcase_01 AC 127 ms
41,332 KB
testcase_02 AC 128 ms
41,404 KB
testcase_03 AC 113 ms
41,316 KB
testcase_04 AC 126 ms
41,420 KB
testcase_05 AC 107 ms
41,300 KB
testcase_06 AC 123 ms
41,136 KB
testcase_07 AC 115 ms
41,492 KB
testcase_08 AC 135 ms
41,616 KB
testcase_09 AC 119 ms
41,628 KB
testcase_10 AC 122 ms
41,684 KB
testcase_11 AC 119 ms
41,480 KB
testcase_12 AC 126 ms
41,512 KB
testcase_13 AC 131 ms
41,688 KB
testcase_14 AC 124 ms
41,784 KB
testcase_15 AC 117 ms
41,576 KB
testcase_16 AC 106 ms
41,696 KB
testcase_17 AC 126 ms
41,340 KB
testcase_18 AC 132 ms
41,392 KB
testcase_19 AC 122 ms
41,368 KB
testcase_20 AC 119 ms
41,472 KB
testcase_21 AC 118 ms
41,696 KB
testcase_22 AC 106 ms
41,724 KB
testcase_23 AC 118 ms
41,328 KB
testcase_24 AC 98 ms
41,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    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 p = (int)Math.sqrt(sum);
        int z = 2*p-1;
        int move = 0;
        for(int i=0; i<N; i++){
            if(i<=p-1){
                int t=A[i]-(i+1);
                if(t>0){
                    move+=t;
                }
            }else if(i<=z-1){
                int t=A[i]-(z-i);
                if(t>0){
                    move+=t;
                }
            }else{
                move+=A[i];
            }
        }
        System.out.println(move);
    }
}
0