結果

問題 No.77 レンガのピラミッド
ユーザー YamaKasaYamaKasa
提出日時 2018-07-03 19:10:35
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 900 bytes
コンパイル時間 3,816 ms
コンパイル使用メモリ 73,388 KB
実行使用メモリ 57,672 KB
最終ジャッジ日時 2023-09-13 17:16:50
合計ジャッジ時間 8,024 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,872 KB
testcase_01 AC 119 ms
55,484 KB
testcase_02 AC 118 ms
56,564 KB
testcase_03 AC 123 ms
55,616 KB
testcase_04 AC 123 ms
55,748 KB
testcase_05 AC 120 ms
56,436 KB
testcase_06 WA -
testcase_07 AC 121 ms
53,752 KB
testcase_08 RE -
testcase_09 AC 120 ms
56,212 KB
testcase_10 AC 123 ms
55,832 KB
testcase_11 AC 129 ms
55,324 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 121 ms
55,720 KB
testcase_16 AC 120 ms
55,768 KB
testcase_17 AC 118 ms
55,972 KB
testcase_18 RE -
testcase_19 AC 118 ms
55,692 KB
testcase_20 AC 118 ms
54,264 KB
testcase_21 AC 125 ms
55,256 KB
testcase_22 AC 122 ms
55,704 KB
testcase_23 AC 124 ms
55,556 KB
testcase_24 AC 125 ms
55,616 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 < 100; i++) {
			if(sum == i * i) {
				n = i;
				break;
			}else if(sum < i * i) {
				n = i - 1;
				break;
			}
		}
		//cost = sum - n * n;
		cost = 0;

		for(int i = 1; i <= 2 * n - 1; 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