結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー mkawa2mkawa2
提出日時 2021-11-05 22:29:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,257 ms / 2,000 ms
コード長 1,312 bytes
コンパイル時間 2,180 ms
コンパイル使用メモリ 199,820 KB
実行使用メモリ 8,808 KB
最終ジャッジ日時 2024-04-25 17:28:55
合計ジャッジ時間 14,444 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,257 ms
8,704 KB
testcase_01 AC 4 ms
7,188 KB
testcase_02 AC 3 ms
7,168 KB
testcase_03 AC 4 ms
7,240 KB
testcase_04 AC 4 ms
7,192 KB
testcase_05 AC 4 ms
7,200 KB
testcase_06 AC 5 ms
7,236 KB
testcase_07 AC 5 ms
7,112 KB
testcase_08 AC 4 ms
7,224 KB
testcase_09 AC 3 ms
7,272 KB
testcase_10 AC 4 ms
7,188 KB
testcase_11 AC 3 ms
7,216 KB
testcase_12 AC 3 ms
7,056 KB
testcase_13 AC 769 ms
8,676 KB
testcase_14 AC 800 ms
8,800 KB
testcase_15 AC 809 ms
8,764 KB
testcase_16 AC 783 ms
8,768 KB
testcase_17 AC 788 ms
8,708 KB
testcase_18 AC 501 ms
8,736 KB
testcase_19 AC 979 ms
8,672 KB
testcase_20 AC 392 ms
8,632 KB
testcase_21 AC 396 ms
8,808 KB
testcase_22 AC 1,054 ms
8,684 KB
testcase_23 AC 254 ms
8,568 KB
testcase_24 AC 247 ms
8,772 KB
testcase_25 AC 741 ms
8,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #include <atcoder/all>
// using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define popcnt(x) __builtin_popcount(x)
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
const int inf = 1e9;
const ll lim = 1e18;
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};

vi factors(int a) {
  vi res;
  for (int f = 1; f * f <= a; f++) {
    if (a % f == 0) {
      res.push_back(f);
      if (f * f != a) res.push_back(a / f);
    }
  }
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int const mx = 1000005;

  // vvi ff(mx, vi(1, 1));
  // for (int f = 2; f < mx; f++) {
  //   for (int i = f; i < mx; i += f) ff[i].push_back(f);
  // }

  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  vi cnt(mx);
  rep(i, n) for (auto f : factors(a[i])) cnt[f]++;

  vi ans(n);
  int r = n;
  for (int f = mx - 1; f > 0; f--) {
    if (r == 0) break;
    if (n - cnt[f] < r) {
      for (int i = n - cnt[f]; i < r; i++) ans[i] = f;
      r = n - cnt[f];
    }
  }
  rep(i, n) cout << ans[i] << endl;

  return 0;
}
0