結果

問題 No.2806 Cornflake Man
ユーザー chro_96chro_96
提出日時 2024-07-12 22:25:35
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 1,286 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 30,592 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-17 20:27:18
合計ジャッジ時間 1,565 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
6,816 KB
testcase_01 AC 53 ms
6,944 KB
testcase_02 AC 8 ms
6,944 KB
testcase_03 AC 56 ms
6,944 KB
testcase_04 AC 7 ms
6,940 KB
testcase_05 AC 13 ms
6,940 KB
testcase_06 AC 18 ms
6,944 KB
testcase_07 AC 69 ms
6,944 KB
testcase_08 AC 16 ms
6,940 KB
testcase_09 AC 33 ms
6,944 KB
testcase_10 AC 19 ms
6,940 KB
testcase_11 AC 5 ms
6,940 KB
testcase_12 AC 22 ms
6,940 KB
testcase_13 AC 44 ms
6,944 KB
testcase_14 AC 10 ms
6,940 KB
testcase_15 AC 52 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

int cmp_int (const void *ap, const void *bp) {
  int a = *(int *)ap;
  int b = *(int *)bp;
  
  if (a < b) {
    return -1;
  }
  
  if (a > b) {
    return 1;
  }
  
  return 0;
}

int main () {
  int n = 0;
  int m = 0;
  int a[200000] = {};
  
  int res = 0;
  
  int ans[200000] = {};
  int cnt = 0;
  int is_ng = 0;
  
  int flag[200000] = {};
  
  res = scanf("%d", &n);
  res = scanf("%d", &m);
  for (int i = 0; i < n; i++) {
    res = scanf("%d", a+i);
  }
  
  qsort(a, n, sizeof(int), cmp_int);
  
  for (int i = 1; i < n; i++) {
    if (is_ng+flag[i] <= 0) {
      int k = 2;
      while (is_ng <= 0 && k*a[i] <= m) {
        int idx[2] = { i, n };
        while (idx[1]-idx[0] > 1) {
          int nxt = (idx[0]+idx[1])/2;
          if (a[nxt] > k*a[i]) {
            idx[1] = nxt;
          } else {
            idx[0] = nxt;
          }
        }
        if (a[idx[0]] == k*a[i]) {
          flag[idx[0]] = 1;
          k++;
        } else {
          is_ng = 1;
        }
      }
      ans[cnt] = a[i];
      cnt++;
    }
  }
  
  if (is_ng > 0) {
    printf("-1\n");
    return 0;
  }
  
  printf("%d\n", cnt);
  printf("%d", ans[0]);
  for (int i = 1; i < cnt; i++) {
    printf(" %d", ans[i]);
  }
  printf("\n");
  return 0;
}
0