結果
問題 |
No.5 数字のブロック
|
ユーザー |
|
提出日時 | 2019-09-01 16:14:38 |
言語 | C (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,528 bytes |
コンパイル時間 | 454 ms |
コンパイル使用メモリ | 29,696 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-28 08:11:49 |
合計ジャッジ時間 | 2,537 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 9 WA * 25 |
ソースコード
#include <stdio.h> #include <string.h> #include <stdlib.h> int main(void) { int boxWidth; int nBlock; // Get boxWidth and nBlock scanf("%d", &boxWidth); scanf("%d", &nBlock); int blockWidths[nBlock]; int nBlockWidth = sizeof blockWidths / sizeof blockWidths[0]; char buffer[256]; rewind(stdin); // clear stdin fgets(buffer, 256, stdin); char *p_buffer; p_buffer = strtok(buffer, " "); // Set blockWidths element int blockWidthsIndex = 0; while(p_buffer != NULL) { int blockWidth = atoi(p_buffer); blockWidths[blockWidthsIndex++] = blockWidth; p_buffer = strtok(NULL, " "); } // bubble-sort blockWidths (asc) int temp; int isChange = 1; // if changed then isChange -> 1 while(isChange == 1) { isChange = 0; for(int i=0; i<nBlockWidth-1; i++) { for(int j=i+1; j<nBlockWidth; j++) { if(blockWidths[i] > blockWidths[j]) { temp = blockWidths[i]; blockWidths[i] = blockWidths[j]; blockWidths[j] = temp; isChange = 1; } } } } // put block in box int nBlockCanIntoBox = 0; int sumWidth = 0; for(int i=0; i<nBlockWidth; i++) { sumWidth += blockWidths[i]; if(sumWidth > boxWidth) { break; } else { nBlockCanIntoBox++; } } printf("%d\n", nBlockCanIntoBox); return 0; }