結果

問題 No.77 レンガのピラミッド
ユーザー YamaKasaYamaKasa
提出日時 2018-07-03 19:14:00
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 920 bytes
コンパイル時間 3,227 ms
コンパイル使用メモリ 75,984 KB
実行使用メモリ 56,716 KB
最終ジャッジ日時 2023-09-13 17:17:39
合計ジャッジ時間 7,353 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
54,644 KB
testcase_01 AC 122 ms
56,716 KB
testcase_02 WA -
testcase_03 AC 120 ms
56,020 KB
testcase_04 AC 119 ms
56,248 KB
testcase_05 AC 120 ms
56,004 KB
testcase_06 AC 129 ms
55,896 KB
testcase_07 AC 119 ms
56,164 KB
testcase_08 AC 134 ms
55,696 KB
testcase_09 AC 121 ms
55,972 KB
testcase_10 AC 121 ms
56,008 KB
testcase_11 AC 122 ms
56,080 KB
testcase_12 AC 127 ms
55,884 KB
testcase_13 AC 128 ms
55,924 KB
testcase_14 AC 126 ms
56,136 KB
testcase_15 AC 123 ms
56,088 KB
testcase_16 AC 122 ms
55,756 KB
testcase_17 AC 120 ms
55,840 KB
testcase_18 AC 125 ms
55,692 KB
testcase_19 AC 118 ms
55,744 KB
testcase_20 AC 119 ms
55,764 KB
testcase_21 AC 128 ms
56,104 KB
testcase_22 AC 124 ms
56,008 KB
testcase_23 AC 127 ms
55,856 KB
testcase_24 AC 120 ms
55,544 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);
		for(int i = 1; i <= N; 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