結果

問題 No.1059 素敵な集合
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2021-01-16 17:14:39
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,682 bytes
コンパイル時間 1,953 ms
コンパイル使用メモリ 108,284 KB
実行使用メモリ 5,460 KB
最終ジャッジ日時 2023-08-18 15:10:26
合計ジャッジ時間 3,873 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,352 KB
testcase_01 AC 30 ms
5,404 KB
testcase_02 AC 4 ms
5,424 KB
testcase_03 AC 3 ms
5,460 KB
testcase_04 AC 2 ms
5,352 KB
testcase_05 AC 3 ms
5,352 KB
testcase_06 AC 5 ms
5,356 KB
testcase_07 AC 4 ms
5,340 KB
testcase_08 AC 5 ms
5,424 KB
testcase_09 AC 3 ms
5,404 KB
testcase_10 AC 7 ms
5,348 KB
testcase_11 AC 4 ms
5,424 KB
testcase_12 AC 4 ms
5,404 KB
testcase_13 AC 7 ms
5,424 KB
testcase_14 AC 2 ms
5,360 KB
testcase_15 AC 11 ms
5,408 KB
testcase_16 AC 4 ms
5,352 KB
testcase_17 AC 4 ms
5,352 KB
testcase_18 AC 2 ms
5,404 KB
testcase_19 AC 29 ms
5,420 KB
testcase_20 AC 29 ms
5,428 KB
testcase_21 AC 10 ms
5,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//
// Created by zeronosu77108 on Jan 15, 2021.
//
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>
#include <complex>
#include <optional>
#include <climits>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<(v)<<endl;}

class UnionFind {
private:
    vector<optional<int>> _par;
    vector<int>_size;
public:
    explicit UnionFind(const int n) : _par(n+1), _size(n+1, 1) {}
    int root(const int x) {
        if (!_par[x]) return x;
        _par[x] = root(_par[x].value());
        return _par[x].value();
    }
    bool is_same(const int x, const int y) {
        return root(x) == root(y);
    }
    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x==y) return false;
        if (_size[x] < _size[y]) swap(x,y);
        _par[y] = x;
        _size[x] += _size[y];
        return true;
    }
    int size(const int x) {
        return _size[x];
    }
};

int main() {
    int l, r;
    cin >> l >>r;
    unordered_map<long, long> mp;

    UnionFind uni(2*100'000);

    for (int i=l; i<=r; i++) {
        for (int j=2*i; j<=r; j+=i) uni.merge(i, j);
    }

    long ans = 0;
    for (int i=l; i<=r; i++) {
        if (i == uni.root(i)) ans++;
    }

    cout << ans - 1 << endl;
}
0