結果

問題 No.826 連絡網
ユーザー PachicobuePachicobue
提出日時 2019-04-23 15:25:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 823 bytes
コンパイル時間 895 ms
コンパイル使用メモリ 86,020 KB
実行使用メモリ 174,424 KB
最終ジャッジ日時 2024-04-22 15:35:00
合計ジャッジ時間 19,310 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 5 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 4 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,526 ms
124,820 KB
testcase_13 AC 360 ms
48,916 KB
testcase_14 AC 958 ms
91,448 KB
testcase_15 AC 36 ms
12,288 KB
testcase_16 AC 520 ms
61,296 KB
testcase_17 AC 342 ms
49,068 KB
testcase_18 AC 244 ms
38,108 KB
testcase_19 AC 1,882 ms
145,008 KB
testcase_20 AC 1,791 ms
141,356 KB
testcase_21 AC 6 ms
5,376 KB
testcase_22 AC 370 ms
49,668 KB
testcase_23 AC 522 ms
63,260 KB
testcase_24 AC 127 ms
28,236 KB
testcase_25 TLE -
testcase_26 AC 189 ms
33,592 KB
testcase_27 AC 1,619 ms
128,724 KB
testcase_28 AC 1,075 ms
97,784 KB
testcase_29 AC 324 ms
48,480 KB
testcase_30 TLE -
testcase_31 AC 466 ms
58,468 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);
    for (int i = 2; i <= N; i++) {
        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