結果
| 問題 | 
                            No.5 数字のブロック
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-09-08 12:04:48 | 
| 言語 | C90  (gcc 12.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 796 bytes | 
| コンパイル時間 | 125 ms | 
| コンパイル使用メモリ | 21,632 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-27 14:53:32 | 
| 合計ジャッジ時間 | 2,115 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 27 WA * 7 | 
コンパイルメッセージ
main.c: In function ‘main’:
main.c:41:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   41 |     scanf("%d%d",&L,&N);
      |     ^~~~~~~~~~~~~~~~~~~
main.c:46:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   46 |         scanf("%d",W+i);
      |         ^~~~~~~~~~~~~~~
            
            ソースコード
#include <stdio.h>
#include <stdlib.h>
#define swap(type,x,y) do{type t=x;x=y;y=t;}while(0)
void bubble(int *W,int N)
{
    int i,j;
    
    for(i=0;i<N;i++){
        int exchg=0;
        for(j=N-1;j>i;j--)
            if(W[j-1]>W[j]){
                swap(int,W[j-1],W[j]);
                exchg++;
            }
        if(exchg==0)break;
    }
}
int count(int *W,int L,int cnt)
{
    int i;
    
    for(i=0,cnt=0;L>0;i++){
        L-=W[i];
        cnt++;
        if(L-W[i+1]<0)
            break;
    }
    
    return cnt;
}
int main(void)
{
    int i,cnt=0;
    int L,N;
    int *W;
    
    scanf("%d%d",&L,&N);
    
    W=calloc(N,sizeof(int));
    
    for(i=0;i<N;i++)
        scanf("%d",W+i);
        
    bubble(W,N);
    
    printf("%d\n",count(W,L,cnt));
    
    return 0;
}