結果
問題 | No.5 数字のブロック |
ユーザー | dazy |
提出日時 | 2016-09-03 16:46:54 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 456 ms / 5,000 ms |
コード長 | 1,501 bytes |
コンパイル時間 | 3,483 ms |
コンパイル使用メモリ | 77,708 KB |
実行使用メモリ | 47,756 KB |
最終ジャッジ日時 | 2024-04-29 07:50:30 |
合計ジャッジ時間 | 12,586 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 129 ms
41,308 KB |
testcase_01 | AC | 127 ms
41,148 KB |
testcase_02 | AC | 116 ms
41,512 KB |
testcase_03 | AC | 344 ms
46,876 KB |
testcase_04 | AC | 314 ms
46,896 KB |
testcase_05 | AC | 364 ms
46,964 KB |
testcase_06 | AC | 334 ms
46,920 KB |
testcase_07 | AC | 306 ms
46,708 KB |
testcase_08 | AC | 351 ms
46,980 KB |
testcase_09 | AC | 241 ms
43,560 KB |
testcase_10 | AC | 396 ms
47,520 KB |
testcase_11 | AC | 310 ms
46,868 KB |
testcase_12 | AC | 354 ms
46,948 KB |
testcase_13 | AC | 376 ms
46,912 KB |
testcase_14 | AC | 143 ms
41,648 KB |
testcase_15 | AC | 155 ms
41,516 KB |
testcase_16 | AC | 402 ms
46,884 KB |
testcase_17 | AC | 456 ms
47,376 KB |
testcase_18 | AC | 451 ms
47,756 KB |
testcase_19 | AC | 426 ms
47,324 KB |
testcase_20 | AC | 113 ms
41,468 KB |
testcase_21 | AC | 129 ms
41,312 KB |
testcase_22 | AC | 111 ms
41,512 KB |
testcase_23 | AC | 125 ms
41,040 KB |
testcase_24 | AC | 154 ms
41,804 KB |
testcase_25 | AC | 188 ms
42,100 KB |
testcase_26 | AC | 127 ms
41,304 KB |
testcase_27 | AC | 128 ms
41,084 KB |
testcase_28 | AC | 132 ms
41,688 KB |
testcase_29 | AC | 316 ms
46,892 KB |
testcase_30 | AC | 232 ms
44,032 KB |
testcase_31 | AC | 119 ms
40,264 KB |
testcase_32 | AC | 127 ms
40,900 KB |
testcase_33 | AC | 126 ms
40,892 KB |
ソースコード
import java.util.Scanner; public class Run { public static void main (String arg[]) { Scanner scan = new Scanner(System.in); int L = scan.nextInt(); int N = scan.nextInt(); if (L < 1||L > 10000||N < 1||N > 10000) System.exit(1); int[] W = new int[N]; for (int i = 0; i < N; i++) { W[i] = scan.nextInt(); if (W[i] < 1||W[i] > L) System.exit(1); } for (int i = N; i > 1; i--) { heapSort(i, W); swap(W, 0, i-1); } int blocks = 0; for (int i = 0; i < N; i++) { L -= W[i]; if (L < 0) break; blocks++; } System.out.println(blocks); } public static void heapSort (int leaf, int[] A) { int root = leaf/2-1; int tmp; for (int i = root; i >= 0; i--) { while ((root+1)*2 <= leaf) { if ((root+1)*2 == leaf) { tmp = (root+1)*2 - 1; } else { if (A[(root+1)*2 - 1] < A[(root+1)*2]) tmp = (root+1)*2; else tmp = (root+1)*2 - 1; } if (A[root] < A[tmp]) { swap(A, root, tmp); root = tmp; } else break; } root = i - 1; } } public static void swap (int[] A, int a, int b){ int tmp; tmp = A[a]; A[a] = A[b]; A[b] = tmp; } }