結果

問題 No.1059 素敵な集合
ユーザー ChanyuhChanyuh
提出日時 2020-08-15 10:29:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 2,450 bytes
コンパイル時間 1,477 ms
コンパイル使用メモリ 137,772 KB
実行使用メモリ 76,416 KB
最終ジャッジ日時 2023-09-30 15:40:04
合計ジャッジ時間 3,463 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 167 ms
76,416 KB
testcase_02 AC 27 ms
11,304 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 20 ms
10,436 KB
testcase_07 AC 20 ms
9,592 KB
testcase_08 AC 28 ms
11,648 KB
testcase_09 AC 7 ms
4,980 KB
testcase_10 AC 37 ms
14,972 KB
testcase_11 AC 21 ms
9,628 KB
testcase_12 AC 11 ms
6,516 KB
testcase_13 AC 43 ms
16,468 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 84 ms
27,688 KB
testcase_16 AC 24 ms
10,308 KB
testcase_17 AC 23 ms
11,280 KB
testcase_18 AC 20 ms
11,144 KB
testcase_19 AC 155 ms
75,420 KB
testcase_20 AC 157 ms
76,264 KB
testcase_21 AC 86 ms
26,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

template<typename T>
struct Kruskal{

  struct edge{
    int from,to;
    T cost;
    int used;
    edge(int from,int to,T cost):
      from(from),to(to),cost(cost),used(0){}
    bool operator<(const edge& e) const{
      return cost<e.cost;
    }
  };
  vector<int> r,p;
  vector<edge> es;
  vector<vector<pair<int,T>>> G;

  Kruskal(){}
  Kruskal(int n):r(n,1),p(n),G(n){
    iota(p.begin(),p.end(),0);
  }

  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }

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

  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }

  void add_edge(int u,int v,T c){
    es.emplace_back(u,v,c);
  }

  T build(){
    sort(es.begin(),es.end());
    T res=0;
    for(auto &e:es){
      if(!same(e.from,e.to)){
        res+=e.cost;
        unite(e.from,e.to);
        G[e.from].push_back(make_pair(e.to,e.cost));
        G[e.to].push_back(make_pair(e.from,e.cost));
        e.used=1;
      }
    }
    return res;
  }

  vector<vector<pair<int,T>>> graph(){
    return G;
  }
};

int l,r;

void solve(){
  cin >> l >> r;
  Kruskal<int> Kru(r-l+1);
  rep(i,r-l+1){
    int t=i+l;
    if(t<r)Kru.add_edge(i,i+1,1);
    for(int j=2*t;j<=r;j+=t){
      Kru.add_edge(i,j-l,0);
    }
  }
  cout << Kru.build() << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}
0