結果
| 問題 |
No.156 キャンディー・ボックス
|
| コンテスト | |
| ユーザー |
sasa
|
| 提出日時 | 2025-03-14 10:37:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 764 bytes |
| コンパイル時間 | 361 ms |
| コンパイル使用メモリ | 28,288 KB |
| 実行使用メモリ | 7,328 KB |
| 最終ジャッジ日時 | 2025-03-14 10:37:29 |
| 合計ジャッジ時間 | 2,228 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 2 |
| other | AC * 7 WA * 23 |
コンパイルメッセージ
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,&sum);
| ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:10:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | scanf("%d",&candy[i]);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
int main(){
// 箱の数・飴をとる数
int box,sum;
scanf("%d%d",&box,&sum);
// 各々の箱に入っている飴の数
int candy[box];
for(int i = 0;i < box;i++){
scanf("%d",&candy[i]);
}
// 一番少ない飴の数
int min = 0;
// 一番少ない飴の要素数
int element = 0;
// 0でない一番先頭の要素数
bool firstflg = false;
for(int j = 0;j < sum;j++){
for(int i = 0;i < box;i++){
if(firstflg == false && candy[i] > 0){
min = candy[i];
element = i;
firstflg = true;
}
if(min > candy[i]){
min = candy[i];
element = i;
}
}
candy[element] -= 1;
firstflg = false;
}
int ans = 0;
for(int i = 0;i < box;i++){
if(candy[i] == 0){
ans++;
}
}
printf("%d",ans);
}
sasa