結果
問題 | No.2806 Cornflake Man |
ユーザー |
![]() |
提出日時 | 2024-07-12 22:25:35 |
言語 | C (gcc 13.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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#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;}