結果

問題 No.77 レンガのピラミッド
ユーザー 37zigen37zigen
提出日時 2020-03-21 22:15:31
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,030 bytes
コンパイル時間 2,156 ms
コンパイル使用メモリ 75,084 KB
実行使用メモリ 56,956 KB
最終ジャッジ日時 2023-08-25 11:10:37
合計ジャッジ時間 6,878 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,592 KB
testcase_01 AC 122 ms
56,956 KB
testcase_02 AC 122 ms
56,228 KB
testcase_03 AC 124 ms
56,176 KB
testcase_04 AC 121 ms
56,124 KB
testcase_05 AC 121 ms
56,204 KB
testcase_06 WA -
testcase_07 AC 118 ms
55,928 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 120 ms
55,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		long t = System.currentTimeMillis();
		new Main().run();
		System.err.println(System.currentTimeMillis() - t);
	}
	
	int solve(int l,int r,int[] A) {
		int sum=0;
		for(int i=0;i<A.length;++i)sum+=A[i];
		if((r-l+1)/2*(r-l+1)/2>sum)return Integer.MAX_VALUE/3;
		int ans=0;
		for(int i=0;i<A.length;++i) {
			if(!(l<=i&&i<r)) {
				ans+=A[i];
			}else {
				int need=Math.min(i-l+1, r-i);
				ans+=Math.max(0, A[i]-need);
			}
		}
		return ans;
	}
	
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int[] A=new int[N];
		for(int i=0;i<N;++i)A[i]=sc.nextInt();
		int ans=Integer.MAX_VALUE/3;
		for(int l=0;l<N;++l) {
			for(int r=l+1;r<=N;r+=2) {
				ans=Math.min(ans,solve(l,r,A));
			}
		}
		System.out.println(ans);
	}


	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}
0