結果

問題 No.826 連絡網
ユーザー koprickykopricky
提出日時 2019-04-23 16:51:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,874 ms / 2,000 ms
コード長 788 bytes
コンパイル時間 856 ms
コンパイル使用メモリ 77,092 KB
実行使用メモリ 114,536 KB
最終ジャッジ日時 2024-04-22 18:14:39
合計ジャッジ時間 15,789 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
26,880 KB
testcase_01 AC 11 ms
26,752 KB
testcase_02 AC 11 ms
26,880 KB
testcase_03 AC 12 ms
27,392 KB
testcase_04 AC 13 ms
27,316 KB
testcase_05 AC 11 ms
27,136 KB
testcase_06 AC 12 ms
27,264 KB
testcase_07 AC 14 ms
27,392 KB
testcase_08 AC 12 ms
27,264 KB
testcase_09 AC 14 ms
27,352 KB
testcase_10 AC 11 ms
27,008 KB
testcase_11 AC 12 ms
27,264 KB
testcase_12 AC 1,244 ms
89,080 KB
testcase_13 AC 300 ms
50,176 KB
testcase_14 AC 844 ms
72,620 KB
testcase_15 AC 37 ms
31,488 KB
testcase_16 AC 471 ms
56,768 KB
testcase_17 AC 268 ms
50,432 KB
testcase_18 AC 199 ms
44,800 KB
testcase_19 AC 1,496 ms
99,456 KB
testcase_20 AC 1,454 ms
98,432 KB
testcase_21 AC 15 ms
27,776 KB
testcase_22 AC 296 ms
50,532 KB
testcase_23 AC 429 ms
57,892 KB
testcase_24 AC 122 ms
39,624 KB
testcase_25 AC 1,853 ms
114,020 KB
testcase_26 AC 153 ms
42,348 KB
testcase_27 AC 1,262 ms
91,264 KB
testcase_28 AC 846 ms
75,560 KB
testcase_29 AC 304 ms
49,792 KB
testcase_30 AC 1,874 ms
114,536 KB
testcase_31 AC 372 ms
55,168 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 main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, p, ans;
    cin >> n >> p;
    for (int i = 2; i <= n; i++) {
        for (int j = 2*i; j <= n; j += i) {
            G[j].push_back(i);
        }
    }
    auto dfs = [&](auto&& self, const int s)->void{
        visit[s] = true, ans++;
        for(int i = 2*s; i <= n; i += s){
            if (!visit[i]) {
                self(self, i);
            }
        }
        for(const int to : G[s]){
            if (!visit[to]) {
                self(self, to);
            }
        }
    };
    dfs(dfs, p);
    cout << ans << "\n";
    return 0;
}
0