結果
問題 | No.5 数字のブロック |
ユーザー |
![]() |
提出日時 | 2015-11-13 01:31:04 |
言語 | C90 (gcc 12.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,163 bytes |
コンパイル時間 | 402 ms |
コンパイル使用メモリ | 22,016 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-13 14:33:29 |
合計ジャッジ時間 | 4,862 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 5 WA * 2 RE * 27 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:70:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 70 | scanf("%d\n%d\n", &L, &n); | ^~~~~~~~~~~~~~~~~~~~~~~~~ main.c:72:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 72 | scanf("%d", &w[i]); | ^~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> void swap(int a[], int i, int j) { int temp; temp = a[i]; a[i] = a[j]; a[j] = temp; } int find_pivot(int a[], int i, int j) { int k = 0; while (i < j) { if (a[i] == a[i + 1]){ if (i != j - 1){ i++; } else{ k = 0; break; } } else { k = a[i] > a[i + 1] ? a[i] : a[i + 1]; break; } } return k; } int partition(int a[], int l, int r, int pivot) { while (1) { while (a[l] < pivot){ l++; } while (a[r] >= pivot){ r--; } if (r >= l){ swap(a, l, r); } else { break; } } return l; } void quicksort(int a[], int i, int j) { int pivot; int k; pivot = find_pivot(a, i, j); if (pivot != 0){ k = partition(a, i, j, pivot); quicksort(a, i, k - 1); quicksort(a, k, j); } } int main() { int L, n, l = 0, m= 0; int w[n]; int i; scanf("%d\n%d\n", &L, &n); for (i = 0; i < n; i++) { scanf("%d", &w[i]); } quicksort(w, 0, n - 1); while (l < L) { if (l + w[m] <= L) { l += w[m]; m++; } else { break; } } printf("%d\n", m); return 0; }