結果

問題 No.50 おもちゃ箱
コンテスト
ユーザー satonakatakumi
提出日時 2021-08-22 15:36:39
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,189 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 89 ms
コンパイル使用メモリ 41,728 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-07-23 01:35:34
合計ジャッジ時間 1,915 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 3
other AC * 5 WA * 33
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'main':
main.c:38:28: warning: passing argument 4 of 'qsort' from incompatible pointer type [-Wincompatible-pointer-types]
   38 |   qsort(b, M, sizeof(i64), comp);
      |                            ^~~~
      |                            |
      |                            i64 (*)(const i64 *, const i64 *) {aka long int (*)(const long int *, const long int *)}
In file included from main.c:2:
/usr/include/stdlib.h:971:34: note: expected '__compar_fn_t' {aka 'int (*)(const void *, const void *)'} but argument is of type 'i64 (*)(const i64 *, const i64 *)' {aka 'long int (*)(const long int *, const long int *)'}
  971 |                    __compar_fn_t __compar) __nonnull ((1, 4));
      |                    ~~~~~~~~~~~~~~^~~~~~~~
main.c:14:5: note: 'comp' declared here
   14 | i64 comp(const i64 *a, const i64 *b)
      |     ^~~~
/usr/include/stdlib.h:948:15: note: '__compar_fn_t' declared here
  948 | typedef int (*__compar_fn_t) (const void *, const void *);
      |               ^~~~~~~~~~~~~

ソースコード

diff #
raw source code

#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 i64 *a, const i64 *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, M, sizeof(i64), 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