結果

問題 No.826 連絡網
ユーザー gazellegazelle
提出日時 2019-05-03 22:55:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,595 bytes
コンパイル時間 1,252 ms
コンパイル使用メモリ 117,828 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2023-08-15 18:25:46
合計ジャッジ時間 3,116 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 41 ms
5,888 KB
testcase_13 AC 16 ms
4,384 KB
testcase_14 AC 31 ms
5,172 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 20 ms
4,504 KB
testcase_17 AC 16 ms
4,380 KB
testcase_18 AC 12 ms
4,380 KB
testcase_19 AC 48 ms
6,396 KB
testcase_20 AC 47 ms
6,156 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 15 ms
4,384 KB
testcase_23 AC 21 ms
4,576 KB
testcase_24 AC 9 ms
4,388 KB
testcase_25 AC 60 ms
6,944 KB
testcase_26 AC 11 ms
4,380 KB
testcase_27 AC 44 ms
5,868 KB
testcase_28 AC 33 ms
5,420 KB
testcase_29 AC 15 ms
4,380 KB
testcase_30 AC 59 ms
6,884 KB
testcase_31 AC 19 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<math.h>
#include<functional>
#include<bitset>
#include<cassert>
using namespace std;
using lint = long long;
using ld = long double;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(lint i=n;i<(int)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

class union_find {
public:
	union_find(int n)
	: par_(n, -1)
	{}
	void init(int n) {
		par_.assign(n, -1);
	}

	int root(int x) {
		return par_[x] < 0 ? x : par_[x] = root(par_[x]);
	}

	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if(x == y) {
			return false;
		} else {
			if(par_[x] < par_[y]) {
				par_[x] += par_[y];
				par_[y] = x;
			} else {
				par_[y] += par_[x];
				par_[x] = y;
			}
			return true;
		}
	}

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

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

private:
	std::vector<int> par_;
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, p;
	cin >> n >> p;
	union_find uf(n);
	for(int i = 2; i <= n; i++) {
		for(int j = 1; i * j <= n; j++) {
			uf.unite(i - 1, i * j - 1);
		}
	}
	cout << (int)uf.size(p - 1) << endl;
	return 0;
}
/* --------------------------------------- */
0