結果

問題 No.77 レンガのピラミッド
ユーザー リチウムリチウム
提出日時 2014-11-26 00:19:21
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 932 bytes
コンパイル時間 2,058 ms
コンパイル使用メモリ 74,636 KB
実行使用メモリ 57,220 KB
最終ジャッジ日時 2023-08-31 01:19:23
合計ジャッジ時間 5,989 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
56,056 KB
testcase_01 AC 104 ms
56,108 KB
testcase_02 AC 104 ms
56,072 KB
testcase_03 AC 103 ms
56,364 KB
testcase_04 AC 105 ms
55,840 KB
testcase_05 AC 99 ms
56,136 KB
testcase_06 WA -
testcase_07 AC 107 ms
56,324 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 103 ms
56,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.lang.Math;

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 ans=Integer.MAX_VALUE;
	  int sum=0;
	  for(int i=0;i<n;i++){
		  a[i]=sc.nextInt();
		  sum+=a[i];
	  }

	  for(int i=1;i<=n;i++){
		  int k=0;
		  int p[]=new int[n];
		  int b[]=new int[n];
		  for(int j=0;j<n;j++){
			  b[j]=a[j];
		  }
		  int x=i/2+1;
		  int y=x*(x+1)-x;
		  if(y>sum)continue;
		  for(int j=0;j<i;j++){
			  if(j<x)p[j]=j+1;
			  else if(j<i) p[j]=i-j;
		  }
		  int s=sum;
		  while(s!=y){
			  for(int j=0;j<n;j++){
				  if(s!=y && b[j]>p[j]){
					  b[j]--;
					  s--;
					  k++;
				  }
			  }
				  
			  }
		  int u=0;
		  for(int j=0;j<n;j++){
			  u+=Math.abs(b[j]-p[j]);
		  }
		  ans=Math.min(ans,k+u/2);
		  }
	  System.out.println(ans);
  }}
0