結果
問題 |
No.156 キャンディー・ボックス
|
ユーザー |
![]() |
提出日時 | 2025-03-14 17:47:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 542 bytes |
コンパイル時間 | 628 ms |
コンパイル使用メモリ | 27,776 KB |
実行使用メモリ | 7,328 KB |
最終ジャッジ日時 | 2025-03-14 17:47:40 |
合計ジャッジ時間 | 1,982 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:6:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 6 | scanf("%d %d", &box, &receive); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:9:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | scanf("%d", &candy[i]); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include<stdio.h> int main() { int box, receive; scanf("%d %d", &box, &receive); int candy[box]; for (int i = 0; i < box; i++){ scanf("%d", &candy[i]); } for (int i = 0; i < box - 1; i++) { if (candy[i] > candy[i + 1]) { candy[i] ^= candy[i + 1]; candy[i + 1] ^= candy[i]; candy[i] ^= candy[i + 1]; if (i > 0) i -= 2; } } int ans = 0; int i = 0; while (receive > 0) { if (candy[i] <= receive) { ans++; receive -= candy[i]; i++; } else receive = 0; } printf("%d\n", ans); return 0; }