結果

問題 No.5 数字のブロック
ユーザー yfujita0929yfujita0929
提出日時 2016-04-10 14:09:52
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 183 ms / 5,000 ms
コード長 1,681 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 22,144 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 07:08:26
合計ジャッジ時間 2,407 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 0 ms
5,376 KB
testcase_02 AC 0 ms
5,376 KB
testcase_03 AC 75 ms
5,376 KB
testcase_04 AC 15 ms
5,376 KB
testcase_05 AC 114 ms
5,376 KB
testcase_06 AC 48 ms
5,376 KB
testcase_07 AC 33 ms
5,376 KB
testcase_08 AC 58 ms
5,376 KB
testcase_09 AC 9 ms
5,376 KB
testcase_10 AC 117 ms
5,376 KB
testcase_11 AC 29 ms
5,376 KB
testcase_12 AC 76 ms
5,376 KB
testcase_13 AC 102 ms
5,376 KB
testcase_14 AC 0 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 119 ms
5,376 KB
testcase_17 AC 165 ms
5,376 KB
testcase_18 AC 133 ms
5,376 KB
testcase_19 AC 183 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 0 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 0 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 0 ms
5,376 KB
testcase_29 AC 13 ms
5,376 KB
testcase_30 AC 10 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 0 ms
5,376 KB
testcase_33 AC 0 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:16:5: warning: ignoring return value of ‘fgets’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |     fgets(str, STR_SIZE, stdin);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:19:5: warning: ignoring return value of ‘fgets’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |     fgets(str, STR_SIZE, stdin);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:23:5: warning: ignoring return value of ‘fgets’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   23 |     fgets(str, STR_SIZE, stdin);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

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

#define STR_SIZE 10000*10000+1

void sortArr(int *arr, int arr_size);
void swap(int *x, int *y);
int simulation(int size, int *arr, int arr_size);

int main(void){
    char *str, *token;
    int box_size, block_num, *block_wid_arr, idx, result;

    str = (char*)calloc(sizeof(char), STR_SIZE);
    fgets(str, STR_SIZE, stdin);
    box_size = atoi(str);

    fgets(str, STR_SIZE, stdin);
    block_num = atoi(str);

    block_wid_arr = (int*)calloc(sizeof(int), block_num);
    fgets(str, STR_SIZE, stdin);
    token = strtok(str, " ");
    for(idx = 0; idx < block_num; idx++) {
        block_wid_arr[idx] = atoi(token);
        token = strtok(NULL, " ");
    }
    
    sortArr(block_wid_arr, block_num);

    /*
    for(idx = 0; idx < block_num; idx++) {
        printf("%d ", block_wid_arr[idx]);
    }
    */
    
    result = simulation(box_size, block_wid_arr, block_num);
    
    printf("%d\n", result);

    free(str);
    free(block_wid_arr);
    
    return 0;
}

void sortArr(int *bw_arr, int arr_size)
{
    int i, j;
    int min;
    
    for(i = 0; i < arr_size; i++) {
        min = 10001;
        for(j = i; j < arr_size; j++) {
            if(bw_arr[j] < min) {
                min = bw_arr[j];
                
                swap(&bw_arr[i], &bw_arr[j]);
            }
        }
    }
}

void swap(int *x, int *y) {
    int tmp;
    
    tmp = *x;
    *x = *y;
    *y = tmp;
}

int simulation(int bs, int *bl_arr, int bls) {
    int i, ret = 0;
    
    for(i = 0; i < bls; i++) {
        bs -= bl_arr[i];
        if(bs < 0) {
            break;
        }
        ret++;
    }
    
    return ret;
}
0