結果

問題 No.50 おもちゃ箱
ユーザー satonakatakumisatonakatakumi
提出日時 2021-08-22 15:34:47
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,204 bytes
コンパイル時間 362 ms
コンパイル使用メモリ 34,048 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 04:46:50
合計ジャッジ時間 1,367 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
5,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1 ms
5,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'main':
main.c:38:41: warning: passing argument 4 of 'qsort' from incompatible pointer type [-Wincompatible-pointer-types]
   38 |   qsort(b, sizeof(b) / sizeof(b[0]), M, comp);
      |                                         ^~~~
      |                                         |
      |                                         i64 (*)(const void *, const void *) {aka long int (*)(const void *, const void *)}
In file included from main.c:2:
/usr/include/stdlib.h:839:34: note: expected '__compar_fn_t' {aka 'int (*)(const void *, const void *)'} but argument is of type 'i64 (*)(const void *, const void *)' {aka 'long int (*)(const void *, const void *)'}
  839 |                    __compar_fn_t __compar) __nonnull ((1, 4));
      |                    ~~~~~~~~~~~~~~^~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <time.h>
#include <math.h>
#include <assert.h>

typedef int64_t i64;
typedef uint64_t u64;
typedef __int128_t i128;
typedef __uint128_t u128;

i64 comp(const void *a, const void *b)
{
  i64 x = *(i64 *)a;
  i64 y = *(i64 *)b;
  return y - x;
}

int main()
{
  int i, j, k;
  int N;
  scanf("%d", &N);
  i64 a[N];
  for (i = 0; i < N; i++)
  {
    scanf("%ld", &a[i]);
  }
  int M;
  scanf("%d", &M);
  i64 b[M];
  for (i = 0; i < M; i++)
  {
    scanf("%ld", &b[i]);
  }
  qsort(b, sizeof(b) / sizeof(b[0]), M, comp);
  bool dp1[1 << 10];
  bool dp2[1 << 10];
  dp1[0] = true;
  for (i = 0; i < M; i++)
  {
    for (j = 0; j < (1 << N); j++)
    {
      i64 c = 0;
      for (k = 0; k < N; k++)
      {
        if ((j >> k) % 2 == 0)
          continue;
        c += a[k];
      }
      if (c > b[M - 1 - i])
        continue;
      for (k = (1 << N) - 1; k >= 0; k--)
      {
        dp2[j | k] |= dp1[k];
      }
    }
    for (k = (1 << N) - 1; k >= 0; k--)
    {
      dp1[k] = dp2[k];
    }
    if (dp1[(1 << N) - 1])
    {
      printf("%d\n", i + 1);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
0