結果

問題 No.5 数字のブロック
ユーザー m0ntBL4Ncm0ntBL4Nc
提出日時 2019-09-01 17:51:40
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,677 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 29,152 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-19 06:20:31
合計ジャッジ時間 2,890 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void) {
    int boxWidth;
    int nBlock;

    // Get boxWidth and nBlock
    scanf("%d", &boxWidth);
    scanf("%d", &nBlock);

    int blockWidths[nBlock];
    int nBlockWidth = sizeof blockWidths / sizeof blockWidths[0];

    char buffer[100000];
    rewind(stdin);      // clear stdin
    fgets(buffer, 100000, stdin);

    char *p_buffer;
    p_buffer = strtok(buffer, " ");

    // Set blockWidths element
    int blockWidthsIndex = 0;
    while(p_buffer != NULL) {
        int blockWidth = atoi(p_buffer);
        blockWidths[blockWidthsIndex++] = blockWidth;
        p_buffer = strtok(NULL, " ");
    }

    // bubble-sort blockWidths (asc)
    int temp;
    int isChange = 1;      // if changed then isChange -> 1
    while(isChange == 1) {
        isChange = 0;
        for(int i=0; i<nBlockWidth-1; i++) {
            for(int j=i+1; j<nBlockWidth; j++) {
                if(blockWidths[i] > blockWidths[j]) {
                    temp = blockWidths[i];
                    blockWidths[i] = blockWidths[j];
                    blockWidths[j] = temp;
                    isChange = 1;
                }
            }
        }
    }

    // printf("\n");
    // for(int i=0; i<10; i++) {
    //     printf("%d\n", blockWidths[i]);
    // }
    // printf("%d\n", nBlockWidth);

    // put block in box
    int nBlockCanIntoBox = 0;
    int sumWidth = 0;
    for(int i=0; i<nBlockWidth; i++) {
        sumWidth += blockWidths[i];
        if(sumWidth > boxWidth) {
            break;
        } else {
            nBlockCanIntoBox++;
        }
    }

    printf("%d\n", nBlockCanIntoBox);
    return 0;
}
0