結果

問題 No.826 連絡網
ユーザー koprickykopricky
提出日時 2019-04-23 16:37:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,701 ms / 2,000 ms
コード長 896 bytes
コンパイル時間 680 ms
コンパイル使用メモリ 72,856 KB
実行使用メモリ 117,016 KB
最終ジャッジ日時 2024-05-03 04:59:46
合計ジャッジ時間 13,533 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
26,752 KB
testcase_01 AC 10 ms
26,880 KB
testcase_02 AC 10 ms
27,008 KB
testcase_03 AC 12 ms
27,264 KB
testcase_04 AC 12 ms
27,392 KB
testcase_05 AC 11 ms
26,880 KB
testcase_06 AC 11 ms
27,008 KB
testcase_07 AC 13 ms
27,392 KB
testcase_08 AC 11 ms
27,136 KB
testcase_09 AC 12 ms
27,392 KB
testcase_10 AC 11 ms
26,752 KB
testcase_11 AC 12 ms
27,136 KB
testcase_12 AC 1,068 ms
90,752 KB
testcase_13 AC 264 ms
50,816 KB
testcase_14 AC 720 ms
73,728 KB
testcase_15 AC 34 ms
31,744 KB
testcase_16 AC 400 ms
57,472 KB
testcase_17 AC 234 ms
50,816 KB
testcase_18 AC 178 ms
45,184 KB
testcase_19 AC 1,251 ms
101,376 KB
testcase_20 AC 1,256 ms
100,096 KB
testcase_21 AC 14 ms
27,648 KB
testcase_22 AC 217 ms
51,200 KB
testcase_23 AC 364 ms
58,752 KB
testcase_24 AC 111 ms
40,192 KB
testcase_25 AC 1,701 ms
116,440 KB
testcase_26 AC 120 ms
42,752 KB
testcase_27 AC 1,014 ms
92,928 KB
testcase_28 AC 757 ms
77,056 KB
testcase_29 AC 251 ms
50,432 KB
testcase_30 AC 1,594 ms
117,016 KB
testcase_31 AC 318 ms
55,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
#include <vector>
#include <cassert>

using namespace std;

const int MAX_N = 1000005;

vector<int> G[MAX_N];
bool visit[MAX_N];
int a[MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, p;
    cin >> n >> p;
    for (int i = 2; i <= n; i++) {
        for (int j = 2*i; j <= n; j += i) {
            G[j].push_back(i);
        }
    }
    int l = 0, r = 0;
    a[r++] = p;
    visit[p] = true;
    int ans = 1;
    while (r-l) {
        const int s = a[l++];
        for(int i = 2*s; i <= n; i += s){
            if (visit[i]) { continue; }
            visit[i] = true;
            a[r++] = i;
            ans++;
        }
        for(const int to : G[s]){
            if (visit[to]) { continue; }
            visit[to] = true;
            a[r++] = to;
            ans++;
        }
    }
    cout << ans << "\n";
    return 0;
}
0