結果

問題 No.1059 素敵な集合
ユーザー shell_mugshell_mug
提出日時 2020-05-22 22:16:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 2,129 bytes
コンパイル時間 1,013 ms
コンパイル使用メモリ 117,300 KB
実行使用メモリ 8,136 KB
最終ジャッジ日時 2023-09-30 15:30:13
合計ジャッジ時間 2,278 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 11 ms
4,380 KB
testcase_02 AC 9 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 6 ms
4,376 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 9 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 7 ms
4,376 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 11 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 18 ms
4,684 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 8 ms
4,376 KB
testcase_18 AC 28 ms
8,136 KB
testcase_19 AC 13 ms
4,416 KB
testcase_20 AC 15 ms
4,520 KB
testcase_21 AC 20 ms
4,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

struct UnionFind {
    vector< int > data;
    UnionFind(int sz) {
        data.assign(sz, -1);
    }
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return (false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }
    int find(int k) {
        if(data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }    
    int size(int k) {
        return (-data[find(k)]);
    }
};

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int l, r; cin >> l >> r;
    UnionFind uf(r - l + 1);
    rep (i, l, r) {
        for (int j = 2; j * i <= r; j++) {
            uf.unite(i - l, i * j - l);
        }
    }
    set<int> st;
    rep (i, l, r + 1) st.insert(uf.find(i - l)); 
    cout << st.size() - 1 << "\n";
    return 0;
}
0