結果

問題 No.1059 素敵な集合
ユーザー niuezniuez
提出日時 2020-05-22 21:54:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,607 bytes
コンパイル時間 1,658 ms
コンパイル使用メモリ 168,248 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 16:40:01
合計ジャッジ時間 2,622 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 15 ms
6,940 KB
testcase_02 AC 4 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 4 ms
6,940 KB
testcase_08 AC 4 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 5 ms
6,940 KB
testcase_11 AC 4 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 5 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 8 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 3 ms
6,944 KB
testcase_18 WA -
testcase_19 AC 15 ms
6,944 KB
testcase_20 AC 15 ms
6,940 KB
testcase_21 AC 8 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<class T, class Cond>
struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  bool operator()(T& a, const T& b) const {
    if(cond(a, b)) { a = b; return true; }
    return false;
  }
};
template<class T, class Cond>
chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); }


#include <vector>
#include <tuple>

struct union_find {
  std::vector<int> par;
  union_find(int N): par(N, -1) {}
  int root(int x) {
    return par[x] < 0 ? x : par[x] = root(par[x]);
  }
  std::tuple<int, int> unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return { -1, -1 };
    if(par[x] > par[y]) std::swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return { x, y };
  }
  int size(int x) {
    return -par[root(x)];
  }
};

int main() {
  i64 L, R;
  cin >> L >> R;

  union_find uf(R + 1);

  std::vector<i64> cost(R + 1, 1);
  for(int i = R + 1; i --> L;) {
    for(int j = i + i; j < R + 1; j += i) {
      uf.unite(i, j);
    }
  }
  i64 ans = 0;
  rep(i,L + 1, R + 1) {
    int r = uf.root(i);
    ans += cost[r];
    cost[r] = 0;
  }
  std::cout << ans - 1 << '\n';
}
0