結果

問題 No.826 連絡網
ユーザー kyort0nkyort0n
提出日時 2019-05-03 21:27:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,421 bytes
コンパイル時間 1,899 ms
コンパイル使用メモリ 170,032 KB
実行使用メモリ 18,948 KB
最終ジャッジ日時 2023-08-15 18:09:37
合計ジャッジ時間 3,797 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
18,732 KB
testcase_01 AC 10 ms
18,716 KB
testcase_02 AC 11 ms
18,540 KB
testcase_03 AC 11 ms
18,624 KB
testcase_04 AC 11 ms
18,816 KB
testcase_05 AC 10 ms
18,576 KB
testcase_06 AC 10 ms
18,556 KB
testcase_07 AC 10 ms
18,792 KB
testcase_08 AC 10 ms
18,564 KB
testcase_09 AC 9 ms
18,760 KB
testcase_10 AC 10 ms
18,620 KB
testcase_11 AC 10 ms
18,624 KB
testcase_12 AC 50 ms
18,876 KB
testcase_13 AC 23 ms
18,800 KB
testcase_14 AC 38 ms
18,748 KB
testcase_15 AC 12 ms
18,628 KB
testcase_16 AC 26 ms
18,560 KB
testcase_17 AC 22 ms
18,796 KB
testcase_18 AC 19 ms
18,560 KB
testcase_19 AC 58 ms
18,820 KB
testcase_20 AC 60 ms
18,696 KB
testcase_21 AC 10 ms
18,748 KB
testcase_22 AC 21 ms
18,948 KB
testcase_23 AC 26 ms
18,740 KB
testcase_24 AC 16 ms
18,796 KB
testcase_25 AC 67 ms
18,704 KB
testcase_26 AC 17 ms
18,780 KB
testcase_27 AC 52 ms
18,800 KB
testcase_28 AC 40 ms
18,600 KB
testcase_29 AC 22 ms
18,572 KB
testcase_30 AC 70 ms
18,600 KB
testcase_31 AC 24 ms
18,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, 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 (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }

    ll size(int x){
        return Size[root(x)];
    }
};


int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, P;
    cin >> N >> P;
    UnionFind uni(1000500);
    for(int i = 2; i <= N; i++) {
        for(int j = 2 * i; j <= N; j += i) {
            uni.merge(j, j - i);
        }
    }
    cout << uni.size(P) << endl;
    return 0;
}
0