結果

問題 No.5 数字のブロック
ユーザー ReERishunReERishun
提出日時 2020-03-23 03:49:40
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,489 bytes
コンパイル時間 121 ms
コンパイル使用メモリ 29,484 KB
実行使用メモリ 5,328 KB
最終ジャッジ日時 2023-08-27 01:21:17
合計ジャッジ時間 3,849 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 119 ms
4,376 KB
testcase_04 AC 75 ms
4,376 KB
testcase_05 AC 206 ms
4,376 KB
testcase_06 AC 80 ms
4,376 KB
testcase_07 AC 53 ms
4,380 KB
testcase_08 AC 105 ms
4,376 KB
testcase_09 AC 12 ms
4,380 KB
testcase_10 AC 243 ms
4,376 KB
testcase_11 AC 50 ms
4,380 KB
testcase_12 AC 130 ms
4,380 KB
testcase_13 AC 192 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 215 ms
4,380 KB
testcase_17 AC 303 ms
4,380 KB
testcase_18 AC 263 ms
4,380 KB
testcase_19 AC 341 ms
4,380 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,384 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 72 ms
4,380 KB
testcase_30 AC 16 ms
4,380 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

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   各ブロックの幅を表す
	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; i++) {
		blockSum += blockWidth[i];
		ans++;
	}
	ans--;

	printf("%d", ans);

	return 0;
}
0