結果

問題 No.826 連絡網
ユーザー mtsdmtsd
提出日時 2019-05-03 21:40:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,376 bytes
コンパイル時間 1,395 ms
コンパイル使用メモリ 79,156 KB
実行使用メモリ 10,832 KB
最終ジャッジ日時 2023-08-15 18:10:56
合計ジャッジ時間 2,473 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 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 49 ms
8,724 KB
testcase_13 AC 17 ms
5,232 KB
testcase_14 AC 36 ms
7,236 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 23 ms
6,052 KB
testcase_17 AC 18 ms
5,524 KB
testcase_18 AC 14 ms
4,832 KB
testcase_19 AC 58 ms
9,640 KB
testcase_20 AC 56 ms
9,480 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 18 ms
5,492 KB
testcase_23 AC 24 ms
6,052 KB
testcase_24 AC 10 ms
4,380 KB
testcase_25 AC 72 ms
10,832 KB
testcase_26 AC 12 ms
4,572 KB
testcase_27 AC 51 ms
8,728 KB
testcase_28 AC 38 ms
7,560 KB
testcase_29 AC 18 ms
5,084 KB
testcase_30 AC 72 ms
10,812 KB
testcase_31 AC 22 ms
5,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
class UnionFind {
private:
    int sz;
    vector<int> par, size_;
public:
    UnionFind(){}
    UnionFind(int node_size) : sz(node_size), par(sz), size_(sz, 1){
        iota(par.begin(), par.end(), 0);
    }
    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }
    void unite(int x,int y){
        x = find(x), y = find(y);
        if(x == y) return;
        if(size_[x] < size_[y]) swap(x,y);
        par[y] = x;
        size_[x] += size_[y];
    }
    int size(int x){
        x = find(x);
        return size_[x];
    }
    bool same(int x,int y){
        return find(x) == find(y);
    }
};
int main(){
    int n,p;
    cin >> n >> p;
    UnionFind uf(n+1);
    for(int i=2;i<=n;i++){
        for(int j=i;j+i<=n;j+=i){
            uf.unite(j,j+i);
        }
    }    
    cout << uf.size(p) << endl;
    return 0;
}
0