結果
| 問題 |
No.5 数字のブロック
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-06-28 22:53:04 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 5,000 ms |
| コード長 | 632 bytes |
| コンパイル時間 | 1,700 ms |
| コンパイル使用メモリ | 159,728 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-18 11:20:42 |
| 合計ジャッジ時間 | 3,205 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
コンパイルメッセージ
main.cpp: In function ‘void gets(int*, int)’:
main.cpp:8:14: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
8 | fgets(buf, sizeof(buf), stdin);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp: In function ‘int main(int, char**)’:
main.cpp:22:14: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
22 | fgets(buf, sizeof(buf), stdin);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:24:14: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
24 | fgets(buf, sizeof(buf), stdin);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
char buf[100000];
void gets(int *a, int n) {
fgets(buf, sizeof(buf), stdin);
char *b = buf;
for (int i = 0; i < n; i++) {
if (1 != sscanf(b, "%d", a + i)) break;
while (*b != '\0' && !isspace(*b)) b++;
while (*b != '\0' && isspace(*b)) b++;
}
}
int W[10000];
int main(int argc, char **argv) {
int L, N;
fgets(buf, sizeof(buf), stdin);
sscanf(buf, "%d", &L);
fgets(buf, sizeof(buf), stdin);
sscanf(buf, "%d", &N);
gets(W, N);
sort(W, W + N);
int i;
for (i = 0; i < N; i++) {
if (L - W[i] < 0) {
break;
}
L -= W[i];
}
printf("%d\n", i);
return 0;
}