結果

問題 No.77 レンガのピラミッド
ユーザー yuya178yuya178
提出日時 2017-06-20 16:46:36
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,658 bytes
コンパイル時間 2,301 ms
コンパイル使用メモリ 78,864 KB
実行使用メモリ 52,540 KB
最終ジャッジ日時 2024-04-10 05:18:31
合計ジャッジ時間 4,294 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int[] b = new int[N+1];
            int sum = 0;
            for(int i=1; i<=N; i++){
                b[i] = in.nextInt();
                sum += b[i];
            }
            int res=0;
            int min=1000000;
            for(int i=1; i<=N; i++){
                if(i%2==0) continue;
                int p = ((i+1)/2)*((i+1)/2);
                if(sum<p) continue;
                for(int j=1; j<=(i+1)/2;j++){
                    res+=Math.max(0,b[j]-j);
                }
                int flag=1;
                for(int j=(i+3)/2; j<=i; j++){
                    res+=Math.max(0,b[j]-((i+1)/2-flag));
                    flag++;
                }
                for(int j=i+1; j<=N; j++){
                    res+=b[j];
                }
                if(res<min) min=res;
                res=0;
            }
            out.println(min);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}
0