結果

問題 No.77 レンガのピラミッド
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-18 01:57:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 138 ms / 5,000 ms
コード長 803 bytes
コンパイル時間 2,515 ms
コンパイル使用メモリ 71,804 KB
実行使用メモリ 56,148 KB
最終ジャッジ日時 2023-08-17 08:26:58
合計ジャッジ時間 7,195 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
56,004 KB
testcase_01 AC 122 ms
55,572 KB
testcase_02 AC 127 ms
55,824 KB
testcase_03 AC 127 ms
55,704 KB
testcase_04 AC 126 ms
55,800 KB
testcase_05 AC 127 ms
55,480 KB
testcase_06 AC 138 ms
55,932 KB
testcase_07 AC 126 ms
55,628 KB
testcase_08 AC 134 ms
55,888 KB
testcase_09 AC 127 ms
55,844 KB
testcase_10 AC 127 ms
55,644 KB
testcase_11 AC 126 ms
55,624 KB
testcase_12 AC 129 ms
56,148 KB
testcase_13 AC 133 ms
55,868 KB
testcase_14 AC 130 ms
55,832 KB
testcase_15 AC 124 ms
55,800 KB
testcase_16 AC 124 ms
55,532 KB
testcase_17 AC 123 ms
55,492 KB
testcase_18 AC 132 ms
55,732 KB
testcase_19 AC 125 ms
56,084 KB
testcase_20 AC 122 ms
55,708 KB
testcase_21 AC 130 ms
55,912 KB
testcase_22 AC 126 ms
55,856 KB
testcase_23 AC 127 ms
55,572 KB
testcase_24 AC 122 ms
55,616 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