結果

問題 No.5 数字のブロック
ユーザー aparachia14aparachia14
提出日時 2016-01-13 23:49:15
言語 Java19
(openjdk 21)
結果
AC  
実行時間 119 ms / 5,000 ms
コード長 1,806 bytes
コンパイル時間 3,968 ms
コンパイル使用メモリ 72,920 KB
実行使用メモリ 52,844 KB
最終ジャッジ日時 2023-08-11 14:31:09
合計ジャッジ時間 6,746 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,408 KB
testcase_01 AC 42 ms
49,364 KB
testcase_02 AC 42 ms
49,200 KB
testcase_03 AC 99 ms
52,440 KB
testcase_04 AC 79 ms
52,424 KB
testcase_05 AC 99 ms
52,708 KB
testcase_06 AC 94 ms
52,248 KB
testcase_07 AC 81 ms
52,440 KB
testcase_08 AC 89 ms
52,676 KB
testcase_09 AC 78 ms
50,592 KB
testcase_10 AC 100 ms
52,612 KB
testcase_11 AC 81 ms
52,240 KB
testcase_12 AC 94 ms
52,420 KB
testcase_13 AC 94 ms
52,844 KB
testcase_14 AC 44 ms
49,424 KB
testcase_15 AC 45 ms
49,504 KB
testcase_16 AC 109 ms
52,352 KB
testcase_17 AC 115 ms
52,484 KB
testcase_18 AC 111 ms
52,820 KB
testcase_19 AC 119 ms
52,576 KB
testcase_20 AC 41 ms
49,504 KB
testcase_21 AC 45 ms
49,716 KB
testcase_22 AC 41 ms
49,456 KB
testcase_23 AC 41 ms
49,552 KB
testcase_24 AC 47 ms
49,592 KB
testcase_25 AC 49 ms
49,380 KB
testcase_26 AC 41 ms
49,372 KB
testcase_27 AC 42 ms
49,332 KB
testcase_28 AC 41 ms
49,372 KB
testcase_29 AC 77 ms
50,056 KB
testcase_30 AC 67 ms
50,312 KB
testcase_31 AC 41 ms
49,308 KB
testcase_32 AC 42 ms
49,676 KB
testcase_33 AC 40 ms
49,188 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