結果
問題 | No.77 レンガのピラミッド |
ユーザー |
|
提出日時 | 2020-03-21 22:15:31 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,030 bytes |
コンパイル時間 | 2,335 ms |
コンパイル使用メモリ | 77,624 KB |
実行使用メモリ | 41,532 KB |
最終ジャッジ日時 | 2024-12-23 17:53:49 |
合計ジャッジ時間 | 6,161 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 3 WA * 17 |
ソースコード
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)); } }