結果

問題 No.719 Coprime
ユーザー 0w10w1
提出日時 2018-09-17 15:11:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 3,000 ms
コード長 1,053 bytes
コンパイル時間 3,369 ms
コンパイル使用メモリ 207,048 KB
実行使用メモリ 4,760 KB
最終ジャッジ日時 2023-09-25 09:23:43
合計ジャッジ時間 5,769 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 2 ms
4,376 KB
testcase_53 AC 2 ms
4,376 KB
testcase_54 AC 3 ms
4,376 KB
testcase_55 AC 4 ms
4,376 KB
testcase_56 AC 6 ms
4,472 KB
testcase_57 AC 6 ms
4,484 KB
testcase_58 AC 7 ms
4,760 KB
testcase_59 AC 7 ms
4,688 KB
testcase_60 AC 7 ms
4,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

signed main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  vector<bool> np(N + 1);
  vector<int> primes;
  vector<int> maxpf(N + 1);
  for (int i = 2; i < np.size(); ++i) {
    if (np[i]) continue;
    primes.emplace_back(i);
    maxpf[i] = i;
    for (int j = i + i; j < np.size(); j += i) {
      np[j] = 1;
      maxpf[j] = max(maxpf[j], i);
    }
  }

  int ni = upper_bound(primes.begin(), primes.end(), N) - primes.begin();
  int si = 0;
  while (primes[si] * primes[si] <= N) ++si;

  vector<vector<int>> dp(ni + 1, vector<int>(1 << si));
  for (int i = 0; i < ni; ++i) {
    dp[~i & 1] = dp[i & 1];
    for (int j = 2; j <= N; ++j) {
      if (maxpf[j] != primes[i]) continue;
      int t = 0;
      for (int k = 0; k < si; ++k)
        if (j % primes[k] == 0) t |= 1 << k;
      for (int s = 0; s < 1 << si; ++s)
        if ((s & t) == 0) dp[~i & 1][s | t] = max(dp[~i & 1][s | t], dp[i & 1][s] + j);
    }
  }

  cout << *max_element(dp[ni & 1].begin(), dp[ni & 1].end()) << endl;
}
0