結果

問題 No.77 レンガのピラミッド
ユーザー 37zigen37zigen
提出日時 2020-03-21 22:27:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 155 ms / 5,000 ms
コード長 1,032 bytes
コンパイル時間 2,261 ms
コンパイル使用メモリ 75,476 KB
実行使用メモリ 56,556 KB
最終ジャッジ日時 2023-08-25 12:49:45
合計ジャッジ時間 7,194 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
55,740 KB
testcase_01 AC 123 ms
56,376 KB
testcase_02 AC 136 ms
55,520 KB
testcase_03 AC 123 ms
55,808 KB
testcase_04 AC 123 ms
55,708 KB
testcase_05 AC 122 ms
55,728 KB
testcase_06 AC 155 ms
55,916 KB
testcase_07 AC 142 ms
55,756 KB
testcase_08 AC 152 ms
56,100 KB
testcase_09 AC 142 ms
56,172 KB
testcase_10 AC 141 ms
53,736 KB
testcase_11 AC 140 ms
55,916 KB
testcase_12 AC 145 ms
56,556 KB
testcase_13 AC 149 ms
55,928 KB
testcase_14 AC 151 ms
53,884 KB
testcase_15 AC 139 ms
55,708 KB
testcase_16 AC 141 ms
55,964 KB
testcase_17 AC 138 ms
55,512 KB
testcase_18 AC 144 ms
53,988 KB
testcase_19 AC 142 ms
55,968 KB
testcase_20 AC 138 ms
56,208 KB
testcase_21 AC 139 ms
55,764 KB
testcase_22 AC 139 ms
55,776 KB
testcase_23 AC 141 ms
55,916 KB
testcase_24 AC 122 ms
55,944 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[200];
		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<=200;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