結果

問題 No.826 連絡網
ユーザー satou_a_mansatou_a_man
提出日時 2019-05-03 22:16:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 949 bytes
コンパイル時間 2,335 ms
コンパイル使用メモリ 200,616 KB
実行使用メモリ 12,240 KB
最終ジャッジ日時 2023-08-15 18:20:27
合計ジャッジ時間 4,488 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,712 KB
testcase_01 AC 4 ms
6,756 KB
testcase_02 AC 4 ms
6,860 KB
testcase_03 AC 5 ms
6,740 KB
testcase_04 AC 5 ms
6,912 KB
testcase_05 AC 4 ms
6,892 KB
testcase_06 AC 4 ms
6,696 KB
testcase_07 AC 4 ms
6,888 KB
testcase_08 AC 4 ms
6,864 KB
testcase_09 AC 5 ms
6,856 KB
testcase_10 AC 5 ms
6,888 KB
testcase_11 AC 4 ms
6,836 KB
testcase_12 AC 74 ms
10,532 KB
testcase_13 AC 27 ms
8,468 KB
testcase_14 AC 54 ms
9,780 KB
testcase_15 AC 8 ms
7,244 KB
testcase_16 AC 34 ms
8,692 KB
testcase_17 AC 27 ms
8,720 KB
testcase_18 AC 21 ms
8,292 KB
testcase_19 AC 86 ms
11,384 KB
testcase_20 AC 85 ms
11,228 KB
testcase_21 AC 5 ms
6,780 KB
testcase_22 AC 27 ms
8,460 KB
testcase_23 AC 36 ms
8,824 KB
testcase_24 AC 16 ms
7,708 KB
testcase_25 AC 105 ms
12,192 KB
testcase_26 AC 18 ms
7,968 KB
testcase_27 AC 77 ms
10,928 KB
testcase_28 AC 58 ms
9,784 KB
testcase_29 AC 27 ms
8,508 KB
testcase_30 AC 108 ms
12,240 KB
testcase_31 AC 32 ms
8,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int MAX_N=1000000;
vector<int> UF=vector<int>(MAX_N+1);
void init() {
    for(int i=0; i<MAX_N+1; i++)
        UF[i]=i;
}
int root(int a) {
    if(UF[a]==a)
        return a;
    return UF[a]=root(UF[a]);
}
void unite(int a, int b) {
  a=root(a);
  b=root(b);
  if(a==b)
    return;
  UF[a]=b;
}
bool same(int a, int b) {
    return root(a)==root(b);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n,p;
  cin>>n>>p;
  init();
  for(int k=2; k<n; k++) {
    int s=k;
    while(s+k<=n) {
      unite(s,s+k);
      s+=k;
    }
  }
  int ans=0;
  for(int x=1; x<=n; x++) {
    if(same(x,p)) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
0