結果

問題 No.5 数字のブロック
ユーザー 0yuduki00yuduki0
提出日時 2015-11-13 01:31:04
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,163 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 25,640 KB
実行使用メモリ 4,480 KB
最終ジャッジ日時 2023-10-11 15:46:30
合計ジャッジ時間 4,421 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 RE -
testcase_02 AC 0 ms
4,352 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 0 ms
4,348 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 RE -
testcase_25 RE -
testcase_26 WA -
testcase_27 AC 0 ms
4,352 KB
testcase_28 AC 0 ms
4,352 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0