結果

問題 No.1059 素敵な集合
ユーザー soto800soto800
提出日時 2020-05-22 22:13:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 835 ms / 2,000 ms
コード長 2,461 bytes
コンパイル時間 1,730 ms
コンパイル使用メモリ 173,856 KB
実行使用メモリ 10,972 KB
最終ジャッジ日時 2023-09-30 15:29:39
合計ジャッジ時間 9,113 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 828 ms
6,540 KB
testcase_02 AC 232 ms
5,108 KB
testcase_03 AC 1 ms
4,504 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 137 ms
4,472 KB
testcase_07 AC 129 ms
4,376 KB
testcase_08 AC 222 ms
4,912 KB
testcase_09 AC 41 ms
4,376 KB
testcase_10 AC 239 ms
4,516 KB
testcase_11 AC 144 ms
4,396 KB
testcase_12 AC 79 ms
4,376 KB
testcase_13 AC 361 ms
5,440 KB
testcase_14 AC 10 ms
4,376 KB
testcase_15 AC 694 ms
6,952 KB
testcase_16 AC 184 ms
4,576 KB
testcase_17 AC 198 ms
4,856 KB
testcase_18 AC 530 ms
10,972 KB
testcase_19 AC 834 ms
6,672 KB
testcase_20 AC 835 ms
6,792 KB
testcase_21 AC 753 ms
7,264 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:33:1: 警告: ‘typedef’ was ignored in this declaration
   33 | typedef struct UnionFind{
      | ^~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
 
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

set<lli> divisorList(lli num){
	set<lli> v;

	for(lli i=1;i*i<=num;i++){
		if(num%i==0){
			v.insert(i);
			v.insert(num/i);
		}
	}
	return v;
}

typedef struct UnionFind{
    vector<lli> par; //par[i]:iの親番号 par[3] = 2 : 3の親が2
    vector<lli> size;//size[i]:iの大きさ 自分のみのときは1,根っこにsizeを持たせる*/

    UnionFind(int N){/*最初はすべてが根であると初期化*/
        REP(i,0,N){
            par.push_back(i);
            size.push_back(1);
        }
    }

    lli root(lli x){/*データxが属する木の根を再起で得る root(x) = {xの木の根}}*/
        if(par[x] == x)return x;
        return par[x] = root(par[x]);
    }

    void unite(lli x,lli y){/*xとyの併合*/
        lli rx = root(x);
        lli ry = root(y);
        if(rx == ry)return;
        par[rx] = ry; /*xとyの根が同じじゃない: xの根をrxをyの根ryに変更する */
        lli resize = size[rx] + size[ry];
        size[rx] = resize;
        size[ry] = resize;
    }

    bool same(lli x,lli y){
        lli rx = root(x);
        lli ry = root(y);
        return rx == ry;
    }

    lli getSize(lli x){
        lli rx = root(x);
        return size[rx];
    }
};

int main(){

	lli ans = 0;

	lli l,r;
	cin>>l>>r;

	UnionFind uf(r+1);
	set<lli> s;

	for(lli i=r;i>l;i--){
		set<lli> prime = divisorList(i);
		for(auto e:prime){
			if(e>=l)uf.unite(i,e);
			LOG4(i,e,uf.root(i),uf.root(e));
		}
	}

	REP(i,l,r+1){
		s.insert(uf.root(i));
	}
	cout<<s.size()-1<<endl;

    return 0;
}
0