結果

問題 No.5 数字のブロック
ユーザー aparachia14aparachia14
提出日時 2016-01-13 23:49:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 139 ms / 5,000 ms
コード長 1,806 bytes
コンパイル時間 3,851 ms
コンパイル使用メモリ 75,020 KB
実行使用メモリ 40,400 KB
最終ジャッジ日時 2024-04-29 06:46:57
合計ジャッジ時間 8,061 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
36,716 KB
testcase_01 AC 54 ms
36,688 KB
testcase_02 AC 52 ms
36,656 KB
testcase_03 AC 102 ms
38,996 KB
testcase_04 AC 97 ms
38,856 KB
testcase_05 AC 109 ms
39,756 KB
testcase_06 AC 103 ms
39,080 KB
testcase_07 AC 96 ms
38,736 KB
testcase_08 AC 109 ms
39,020 KB
testcase_09 AC 83 ms
38,152 KB
testcase_10 AC 121 ms
40,040 KB
testcase_11 AC 99 ms
38,616 KB
testcase_12 AC 104 ms
38,936 KB
testcase_13 AC 115 ms
39,848 KB
testcase_14 AC 53 ms
36,940 KB
testcase_15 AC 54 ms
36,828 KB
testcase_16 AC 121 ms
40,084 KB
testcase_17 AC 124 ms
40,400 KB
testcase_18 AC 122 ms
40,064 KB
testcase_19 AC 139 ms
40,312 KB
testcase_20 AC 53 ms
36,820 KB
testcase_21 AC 54 ms
36,832 KB
testcase_22 AC 53 ms
36,700 KB
testcase_23 AC 53 ms
36,984 KB
testcase_24 AC 60 ms
37,284 KB
testcase_25 AC 61 ms
37,716 KB
testcase_26 AC 54 ms
36,676 KB
testcase_27 AC 54 ms
36,460 KB
testcase_28 AC 55 ms
36,840 KB
testcase_29 AC 98 ms
38,900 KB
testcase_30 AC 88 ms
38,392 KB
testcase_31 AC 53 ms
36,580 KB
testcase_32 AC 53 ms
36,984 KB
testcase_33 AC 52 ms
36,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

//No.5数字のブロック
public class NumberBlock {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		//大きな箱の幅
		int widthOfBox;
		//ブロックの数
		int numberOfBlock;
		//各ブロックの幅
		ArrayList<Integer> widthOfBlock = new ArrayList<Integer>();
		
		//入力値の取得
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		widthOfBox = Integer.parseInt(in.readLine());
		numberOfBlock = Integer.parseInt(in.readLine());
		String[] temp = in.readLine().split(" ");
		
		//tempをバラし、int型に直しwidthOfBoxに格納する。
		for(String width : temp){
			widthOfBlock.add(Integer.parseInt(width));
		}
		
		//ArrayListから最小値を求め、その値をwidthOfBoxから減算し、その後ArrayListからその値を除外する。
		//この処理をwidthOfBoxの値が0以下になるまで繰り返す。
		int min;//最小値格納変数
		int counter; //カウンタ
		int counter2 = 0;//第二カウンタ
		int index = 0;//削除対象要素番号格納変数
		int capacity = widthOfBox;
		while(true){
			min = widthOfBox;
			counter = 0;
			
			//配列から最小値を求める。
			for(int width2 : widthOfBlock){
				if(min > width2){//width2の方がminより値が小さければminに格納
					min = width2;
					index = counter;//削除対象の要素番号を記憶
				}else{
					
				}
				counter++;
			}
			
			if(capacity - min >= 0){
				capacity = capacity - min; 
				counter2++;
			}else{
				break;
			}
			
			widthOfBlock.remove(index);//ArrayListから削除
		}
		
		System.out.println(counter2);

	}

}
0