結果

問題 No.77 レンガのピラミッド
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-24 17:46:04
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,238 bytes
コンパイル時間 2,142 ms
コンパイル使用メモリ 74,176 KB
実行使用メモリ 57,792 KB
最終ジャッジ日時 2023-09-18 09:01:53
合計ジャッジ時間 6,633 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 127 ms
55,672 KB
testcase_05 AC 128 ms
55,872 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 WA -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner koko = new Scanner(System.in);
        int n = koko.nextInt();
        int[] a = new int[n];
        int total =0;
        for(int i=0; i<n; i++){
            a[i]=koko.nextInt();
            total=total+a[i];
        }
        int idou = total;
        int c = 1;
        for(int i=1; i*i<=total; i+=2){
            int put=0;
            int rem=0;
            for(int j=0; j<(i-1)/2; j++){
                if(a[j]<=c){
                    put=put+c-a[j];
                }else{
                    rem=rem+a[j]-c;
                }
                c++;
            }
            for(int j=(i-1)/2; j<i-1; j++){
                if(a[j]<=c){
                    put=put+c-a[j];
                }else{
                    rem=rem+a[j]-c;
                }
                c--;
            }
            if(a[i-1]<=c){
                    put=put+c-a[i-1];
                }else{
                    rem=rem+a[i-1]-c;
                }
            for(int j=i; j<n; j++){
                rem=rem+a[j];
            }
            idou=Math.min(idou, Math.max(rem, put));
        }
        System.out.println(idou);
    }
}
0