結果

問題 No.1059 素敵な集合
ユーザー imoni_kawaiiimoni_kawaii
提出日時 2020-06-08 18:47:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,231 bytes
コンパイル時間 2,043 ms
コンパイル使用メモリ 200,232 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-30 15:39:15
合計ジャッジ時間 3,029 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using ll = long long;
using ld = long double;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }

struct UnionFind {
  vector<int> data;
  UnionFind(int n) : data(n, -1) {}

  int root(int x) {
    if(data[x] < 0) return x;
    return data[x] = root(data[x]);
  }

  bool unite(int x, int y) {
    x = root(x), y = root(y);
    if(x == y) return false;
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return true;
  }

  int same(int x, int y) {
    return root(x) == root(y);
  }

  int size(int x) {
    return -data[root(x)];
  }
};


int l, r;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  cin >> l >> r;
  UnionFind uf(r-l+1);
  REP(i, l, r+1) {
    if(uf.root(i-l) != i-l) continue;
    for(ll j = i*2; j <= r; j += i) {
      uf.unite(i-l, j-l);
    }
  }
  ll ans = 0;
  rep(i, r-l+1) if(uf.root(i) == i) ans++;
  ans--;
  cout << ans << '\n';
  return 0;
}
0