結果
| 問題 |
No.5 数字のブロック
|
| ユーザー |
|
| 提出日時 | 2019-09-08 12:06:45 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
AC
|
| 実行時間 | 145 ms / 5,000 ms |
| コード長 | 809 bytes |
| コンパイル時間 | 156 ms |
| コンパイル使用メモリ | 21,888 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-27 14:53:34 |
| 合計ジャッジ時間 | 2,129 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
コンパイルメッセージ
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 N,int cnt)
{
int i;
for(i=0,cnt=0;L>0&&i<N;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,N,cnt));
return 0;
}