結果

問題 No.826 連絡網
ユーザー koprickykopricky
提出日時 2019-04-23 16:39:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,807 ms / 2,000 ms
コード長 958 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 77,316 KB
実行使用メモリ 116,480 KB
最終ジャッジ日時 2024-04-22 18:01:45
合計ジャッジ時間 14,605 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
26,880 KB
testcase_01 AC 17 ms
26,880 KB
testcase_02 AC 18 ms
26,880 KB
testcase_03 AC 18 ms
27,520 KB
testcase_04 AC 21 ms
27,520 KB
testcase_05 AC 19 ms
27,136 KB
testcase_06 AC 19 ms
27,136 KB
testcase_07 AC 20 ms
27,392 KB
testcase_08 AC 21 ms
27,008 KB
testcase_09 AC 20 ms
27,520 KB
testcase_10 AC 19 ms
27,136 KB
testcase_11 AC 20 ms
27,264 KB
testcase_12 AC 1,093 ms
90,240 KB
testcase_13 AC 257 ms
50,304 KB
testcase_14 AC 733 ms
72,960 KB
testcase_15 AC 43 ms
31,616 KB
testcase_16 AC 380 ms
56,832 KB
testcase_17 AC 267 ms
50,560 KB
testcase_18 AC 174 ms
45,056 KB
testcase_19 AC 1,367 ms
100,992 KB
testcase_20 AC 1,361 ms
98,816 KB
testcase_21 AC 22 ms
27,648 KB
testcase_22 AC 259 ms
50,688 KB
testcase_23 AC 419 ms
58,624 KB
testcase_24 AC 118 ms
39,936 KB
testcase_25 AC 1,807 ms
115,584 KB
testcase_26 AC 147 ms
42,624 KB
testcase_27 AC 1,216 ms
91,904 KB
testcase_28 AC 771 ms
75,776 KB
testcase_29 AC 253 ms
50,304 KB
testcase_30 AC 1,750 ms
116,480 KB
testcase_31 AC 353 ms
55,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
#include <vector>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC target("avx")

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;
    cin >> n >> p;
    for (int i = 2; i <= n; i++) {
        for (int j = 2*i; j <= n; j += i) {
            G[j].push_back(i);
        }
    }
    queue<int> q;
    q.push(p);
    visit[p] = true;
    int ans = 1;
    while (not q.empty()) {
        const int s = q.front();
        q.pop();
        for(int i = 2*s; i <= n; i += s){
            if (visit[i]) { continue; }
            visit[i] = true;
            q.push(i);
            ans++;
        }
        for(const int to : G[s]){
            if (visit[to]) { continue; }
            visit[to] = true;
            q.push(to);
            ans++;
        }
    }
    cout << ans << "\n";
    return 0;
}
0