結果

問題 No.826 連絡網
ユーザー PachicobuePachicobue
提出日時 2019-04-23 15:32:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 945 bytes
コンパイル時間 894 ms
コンパイル使用メモリ 86,280 KB
実行使用メモリ 174,680 KB
最終ジャッジ日時 2024-04-22 15:47:01
合計ジャッジ時間 18,072 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 6 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 1,465 ms
124,780 KB
testcase_13 AC 376 ms
48,952 KB
testcase_14 AC 881 ms
91,644 KB
testcase_15 AC 36 ms
12,288 KB
testcase_16 AC 451 ms
61,336 KB
testcase_17 AC 388 ms
49,100 KB
testcase_18 AC 247 ms
38,240 KB
testcase_19 AC 1,775 ms
144,984 KB
testcase_20 AC 1,705 ms
141,588 KB
testcase_21 AC 7 ms
5,376 KB
testcase_22 AC 380 ms
49,832 KB
testcase_23 AC 503 ms
63,436 KB
testcase_24 AC 128 ms
28,128 KB
testcase_25 TLE -
testcase_26 AC 175 ms
33,620 KB
testcase_27 AC 1,518 ms
128,940 KB
testcase_28 AC 1,137 ms
97,736 KB
testcase_29 AC 365 ms
48,640 KB
testcase_30 TLE -
testcase_31 AC 474 ms
58,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
#include <vector>
#include <cassert>
int main()
{
    int N, P;
    std::cin >> N >> P;
    assert(1 <= N and N <= 1000000);
    assert(1 <= P and P <= N);
    std::vector<std::vector<int>> G(N + 1);
    std::vector<bool> isPrime(N + 1, true);
    isPrime[0] = isPrime[1] = true;
    for (int i = 2; i <= N; i++) {
        if (not isPrime[i]) { continue; }
        for (int j = 2; i * j <= N; j++) {
            G[i].push_back(i * j);
            G[i * j].push_back(i);
        }
    }
    std::vector<bool> visited(N + 1, false);
    std::queue<int> Q;
    Q.push(P);
    visited[P] = true;
    int ans = 1;
    while (not Q.empty()) {
        const int s = Q.front();
        Q.pop();
        for (const int to : G[s]) {
            if (visited[to]) { continue; }
            visited[to] = true;
            Q.push(to);
            ans++;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}
0