結果

問題 No.1416 ショッピングモール
ユーザー ks2mks2m
提出日時 2021-03-05 22:20:38
言語 Java19
(openjdk 21)
結果
AC  
実行時間 398 ms / 1,000 ms
コード長 524 bytes
コンパイル時間 6,738 ms
コンパイル使用メモリ 72,064 KB
実行使用メモリ 60,424 KB
最終ジャッジ日時 2023-07-29 02:28:03
合計ジャッジ時間 13,169 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
56,168 KB
testcase_01 AC 122 ms
56,112 KB
testcase_02 AC 125 ms
55,780 KB
testcase_03 AC 132 ms
57,980 KB
testcase_04 AC 125 ms
55,880 KB
testcase_05 AC 158 ms
56,120 KB
testcase_06 AC 132 ms
55,864 KB
testcase_07 AC 172 ms
55,968 KB
testcase_08 AC 180 ms
56,052 KB
testcase_09 AC 121 ms
55,864 KB
testcase_10 AC 120 ms
55,960 KB
testcase_11 AC 197 ms
58,468 KB
testcase_12 AC 164 ms
55,756 KB
testcase_13 AC 199 ms
58,544 KB
testcase_14 AC 207 ms
59,900 KB
testcase_15 AC 220 ms
59,524 KB
testcase_16 AC 204 ms
59,096 KB
testcase_17 AC 242 ms
59,580 KB
testcase_18 AC 234 ms
60,264 KB
testcase_19 AC 238 ms
59,516 KB
testcase_20 AC 237 ms
59,540 KB
testcase_21 AC 389 ms
60,204 KB
testcase_22 AC 393 ms
60,252 KB
testcase_23 AC 398 ms
60,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
	public static void main(String[] args) throws Exception {
		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();
		}
		sc.close();

		Arrays.sort(a);
		int f = 0;
		int m = 1;
		int c = 0;
		int ans = 0;
		for (int i = n - 1; i >= 0; i--) {
			if (c == m) {
				f++;
				m = 1 << f;
				c = 0;
			}
			ans += a[i] * f;
			c++;
		}
		System.out.println(ans);
	}
}
0