結果

問題 No.5 数字のブロック
ユーザー ReERishunReERishun
提出日時 2020-03-23 05:15:07
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 328 ms / 5,000 ms
コード長 1,597 bytes
コンパイル時間 226 ms
コンパイル使用メモリ 30,008 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 01:22:19
合計ジャッジ時間 3,885 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 119 ms
4,380 KB
testcase_04 AC 72 ms
4,380 KB
testcase_05 AC 199 ms
4,376 KB
testcase_06 AC 79 ms
4,376 KB
testcase_07 AC 53 ms
4,376 KB
testcase_08 AC 103 ms
4,380 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 234 ms
4,376 KB
testcase_11 AC 49 ms
4,380 KB
testcase_12 AC 125 ms
4,380 KB
testcase_13 AC 188 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 210 ms
4,376 KB
testcase_17 AC 293 ms
4,376 KB
testcase_18 AC 244 ms
4,376 KB
testcase_19 AC 328 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 0 ms
4,380 KB
testcase_27 AC 0 ms
4,376 KB
testcase_28 AC 0 ms
4,376 KB
testcase_29 AC 72 ms
4,380 KB
testcase_30 AC 16 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>

// 区切り文字
void numin(int index, int numBox[10000]) {
	char str;
	for (int i = 0; i<index; i++)
		numBox[i] = 0;
	for (int i = 0; i<index; i++) {
		for (int j = 0;; j++) {
			str = getchar();
			if (str == '\n' && i == 0) {
				i = -1;
				break;
			}
			else if (str == '\n' && i != 0) {
				i = index;
				break;
			}
			else if (str < '0' || str > '9') {
				break;
			}
			else
				numBox[i] = numBox[i] * 10 + (int)str - (int)'0';
		}
	}
	return;
}

int main() {

	// 変数宣言
	int boxWidth = 0;
	int blockNum = 0;
	int blockWidth[10000];
	int ans = 0;

	// L    大きな箱の幅を表す
	scanf("%d", &boxWidth);

	// N    ブロックの数を表す
	scanf("%d", &blockNum);

	// W1 W2...WN   各ブロックの幅を表す
	if (blockNum == 1) {
		scanf("%d", &blockWidth[0]);
	}else{
		numin(blockNum, blockWidth);
	}

	// エラー処理
	if (boxWidth > 10000) {
		return 1;
	}
	if (blockNum > 10000) {
		return 1;
	}

	// 各ブロックをソート
	int cnt = 0;
	int put = 0;
	int flg = 0;
	
	if (blockNum != 1) {
		while (1) {
			if (blockWidth[cnt]>blockWidth[cnt + 1]) {
				put = blockWidth[cnt];
				blockWidth[cnt] = blockWidth[cnt + 1];
				blockWidth[cnt + 1] = put;
				flg = 1;
			}

			cnt++;

			if (cnt >= blockNum - 1) {
				if (flg == 0) {
					break;
				}
				else {
					cnt = 0;
					flg = 0;
				}
			}
		}
	}

	// ブロックをはめる
	int blockSum = 0;
	for (int i = 0; blockSum < boxWidth && ans < blockNum; i++) {
		blockSum += blockWidth[i];
		ans++;
	}
	if(blockSum > boxWidth)
		ans--;

	printf("%d", ans);

	return 0;
}
0