結果

問題 No.2806 Cornflake Man
コンテスト
ユーザー tnakao0123
提出日時 2024-07-15 15:42:45
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 1,129 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 311 ms
コンパイル使用メモリ 74,024 KB
実行使用メモリ 11,948 KB
最終ジャッジ日時 2026-07-05 07:18:28
合計ジャッジ時間 6,667 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other AC * 13 TLE * 1 -- * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 2806.cc:  No.2806 Cornflake Man - yukicoder
 */

#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

using ll = long long;
using vi = vector<int>;

/* global variables */

int as[MAX_N], bs[MAX_N], xs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  sort(as + 1, as + n);

  int k = 0;
  vi ds;
  
  for (int i = 1; i < n; i++) {
    int c = 0;
    vi tmp;
    for (auto j: ds) {
      if (as[i] % bs[j] == 0) {
	if (bs[j] * xs[j] != as[i]) { puts("-1"); return 0; }
	c++;
	xs[j]++;
      }
      if (bs[j] * xs[j] <= m) tmp.push_back(j);
    }
    swap(ds, tmp);

    if (c == 0) {
      if (m / as[i] > n - i) { puts("-1"); return 0; }
      bs[k] = as[i], xs[k] = 2;
      ds.push_back(k);
      k++;
    }
  }

  for (int j = 0; j < k; j++)
    if (bs[j] * xs[j] <= m) { puts("-1"); return 0; }

  printf("%d\n", k);
  for (int j = 0; j < k; j++)
    printf("%d%c", bs[j], (j + 1 < k) ? ' ' : '\n');
  
  return 0;
}
0