結果

問題 No.826 連絡網
ユーザー 0w10w1
提出日時 2020-11-15 02:51:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 389 ms / 2,000 ms
コード長 630 bytes
コンパイル時間 1,988 ms
コンパイル使用メモリ 202,476 KB
実行使用メモリ 14,800 KB
最終ジャッジ日時 2023-09-30 06:43:40
合計ジャッジ時間 6,959 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 252 ms
11,384 KB
testcase_13 AC 82 ms
6,484 KB
testcase_14 AC 175 ms
9,444 KB
testcase_15 AC 15 ms
4,376 KB
testcase_16 AC 107 ms
7,212 KB
testcase_17 AC 80 ms
6,468 KB
testcase_18 AC 60 ms
5,628 KB
testcase_19 AC 303 ms
12,936 KB
testcase_20 AC 292 ms
12,748 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 83 ms
6,608 KB
testcase_23 AC 112 ms
7,500 KB
testcase_24 AC 42 ms
4,968 KB
testcase_25 AC 389 ms
14,800 KB
testcase_26 AC 53 ms
5,492 KB
testcase_27 AC 263 ms
11,648 KB
testcase_28 AC 189 ms
9,836 KB
testcase_29 AC 80 ms
6,444 KB
testcase_30 AC 389 ms
14,688 KB
testcase_31 AC 102 ms
7,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, P; {
    cin >> N >> P;
  }

  vector<int> sz(N + 1, 1);
  vector<int> fa(N + 1); {
    iota(fa.begin(), fa.end(), 0);
  }
  function<int(int)> find = [&](int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); };
  function<void(int, int)> unite = [&](int x, int y) {
    int fx = find(x);
    int fy = find(y);
    if (fx == fy) return;
    sz[fx] += sz[fy];
    fa[fy] = fx;
  };

  vector<int> np(N + 1); {
    for (int i = 2; i <= N; ++i) {
      for (int j = i + i; j <= N; j += i) {
        unite(i, j);
      }
    }
  }

  cout << sz[find(P)] << endl;
}
0