結果

問題 No.77 レンガのピラミッド
ユーザー YamaKasaYamaKasa
提出日時 2018-07-03 19:18:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 133 ms / 5,000 ms
コード長 993 bytes
コンパイル時間 1,890 ms
コンパイル使用メモリ 74,392 KB
実行使用メモリ 55,964 KB
最終ジャッジ日時 2023-09-13 17:17:46
合計ジャッジ時間 6,152 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,724 KB
testcase_01 AC 126 ms
53,704 KB
testcase_02 AC 120 ms
55,728 KB
testcase_03 AC 119 ms
55,928 KB
testcase_04 AC 119 ms
55,432 KB
testcase_05 AC 118 ms
55,772 KB
testcase_06 AC 129 ms
55,756 KB
testcase_07 AC 118 ms
55,508 KB
testcase_08 AC 133 ms
55,872 KB
testcase_09 AC 128 ms
55,752 KB
testcase_10 AC 128 ms
55,892 KB
testcase_11 AC 123 ms
55,780 KB
testcase_12 AC 128 ms
55,568 KB
testcase_13 AC 129 ms
55,740 KB
testcase_14 AC 130 ms
55,672 KB
testcase_15 AC 124 ms
55,580 KB
testcase_16 AC 122 ms
55,832 KB
testcase_17 AC 124 ms
55,508 KB
testcase_18 AC 128 ms
55,676 KB
testcase_19 AC 120 ms
55,964 KB
testcase_20 AC 120 ms
55,824 KB
testcase_21 AC 129 ms
55,752 KB
testcase_22 AC 124 ms
55,628 KB
testcase_23 AC 125 ms
55,528 KB
testcase_24 AC 120 ms
55,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int A[] = new int[101];
		Arrays.fill(A, 0);
		// 1オリジン
		for(int i = 1; i <= N; i++) {
			A[i] = scan.nextInt();
		}

		scan.close();

		int sum = 0;
		for(int i = 1; i <= N; i++) {
			sum += A[i];
		}
		int n = 1;
		int cost = 0;
		for(int i = 1; i < 1000; i++) {
			if(sum == i * i) {
				n = i;
				break;
			}else if(sum < i * i) {
				n = i - 1;
				break;
			}
		}
		//cost = sum - n * n;
		cost = 0;
		// System.out.println(n);
		int l;
		if(2 * n - 1>= N) {
			l = N;
		}else {
			l = 2 * n - 1;
		}
		for(int i = 1; i <= l; i++) {
			if(i <= n) {
				if(A[i] >= i) {
					cost += i;
				}else {
					cost += A[i];
				}
			}else {
				int t = 2 * n - i;
				if(A[i] >= t) {
					cost += t;
				}else {
					cost += A[i];
				}
			}
		}

		int ans = sum - cost;
		System.out.println(ans);
	}
}
0