結果
問題 | No.77 レンガのピラミッド |
ユーザー |
![]() |
提出日時 | 2020-12-07 17:48:26 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 125 ms / 5,000 ms |
コード長 | 1,191 bytes |
コンパイル時間 | 1,870 ms |
コンパイル使用メモリ | 77,144 KB |
実行使用メモリ | 54,360 KB |
最終ジャッジ日時 | 2024-09-17 13:59:09 |
合計ジャッジ時間 | 5,783 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 20 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[1000]; int total = 0; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); total += arr[i]; } int min = Integer.MAX_VALUE; for (int i = 1; ; i += 2) { int height = i / 2 + 1; if (height * height > total) { break; } int length = height * 2 - 1; int count = 0; int size = 1; int idx = 1; while (idx < arr.length) { if (arr[idx - 1] == 0 && size == 0) { break; } count += Math.max(arr[idx - 1] - size, 0); if (idx >= height) { size--; if (size < 0) { size = 0; } } else { size++; } idx++; } min = Math.min(min, count); } System.out.println(min); } }