結果

問題 No.5 数字のブロック
コンテスト
ユーザー nanatutmc
提出日時 2019-09-20 01:06:50
言語 C11(gcc12 gnu拡張)
(gcc 12.4.0)
コンパイル:
gcc-12 -O2 -std=gnu11 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 333 ms / 5,000 ms
コード長 736 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 122 ms
コンパイル使用メモリ 32,468 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-03-08 16:21:11
合計ジャッジ時間 3,024 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:3:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
    3 | main() {
      | ^~~~
main.c: In function ‘main’:
main.c:6:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |     scanf("%d", &L);
      |     ^~~~~~~~~~~~~~~
main.c:7:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |     scanf("%d", &N);
      |     ^~~~~~~~~~~~~~~
main.c:10:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         scanf("%d", &(width[i]));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <stdio.h>

main() {
    int L, N;
    int width[10000];
    scanf("%d", &L);
    scanf("%d", &N);
    
    for (int i=0; i<N; i++) {
        scanf("%d", &(width[i]));
    }
    
    // sort
    while (1) {
        int flag = 0;
        for (int i=0; i<N-1; i++) {
            if (width[i] > width[i+1]) {
                int tmp = width[i];
            
                width[i] = width[i+1];
                width[i+1] = tmp;
                flag = 1;
            }
        }
        if (flag == 0)
            break;
    }
    
    int total = 0;
    for (int i = 0; i<N; i++) {
        total += width[i];
        if (total > L) {
            printf("%d\n", i);
            return 0;
        }
    }
    printf("%d\n", N);
}
0