結果

問題 No.826 連絡網
ユーザー koprickykopricky
提出日時 2019-04-23 17:07:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,395 ms / 2,000 ms
コード長 1,202 bytes
コンパイル時間 808 ms
コンパイル使用メモリ 76,792 KB
実行使用メモリ 98,496 KB
最終ジャッジ日時 2024-04-23 00:52:09
合計ジャッジ時間 11,815 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
27,008 KB
testcase_01 AC 9 ms
26,880 KB
testcase_02 AC 8 ms
27,052 KB
testcase_03 AC 10 ms
27,264 KB
testcase_04 AC 11 ms
27,392 KB
testcase_05 AC 8 ms
26,916 KB
testcase_06 AC 9 ms
27,008 KB
testcase_07 AC 11 ms
27,264 KB
testcase_08 AC 9 ms
27,392 KB
testcase_09 AC 10 ms
27,392 KB
testcase_10 AC 9 ms
26,944 KB
testcase_11 AC 10 ms
27,264 KB
testcase_12 AC 853 ms
77,040 KB
testcase_13 AC 197 ms
44,928 KB
testcase_14 AC 567 ms
62,848 KB
testcase_15 AC 35 ms
30,464 KB
testcase_16 AC 270 ms
49,912 KB
testcase_17 AC 195 ms
45,312 KB
testcase_18 AC 140 ms
40,668 KB
testcase_19 AC 1,078 ms
85,632 KB
testcase_20 AC 1,051 ms
83,740 KB
testcase_21 AC 14 ms
27,520 KB
testcase_22 AC 206 ms
45,312 KB
testcase_23 AC 296 ms
51,840 KB
testcase_24 AC 86 ms
36,992 KB
testcase_25 AC 1,395 ms
97,552 KB
testcase_26 AC 113 ms
38,980 KB
testcase_27 AC 884 ms
78,336 KB
testcase_28 AC 606 ms
65,152 KB
testcase_29 AC 192 ms
44,928 KB
testcase_30 AC 1,390 ms
98,496 KB
testcase_31 AC 261 ms
49,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

const int MAX_N = 1000005;
const int M = 30;

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;
    vector<int> a;
    for(int i = 2; i <= M; i++) a.push_back(i);
    for (int i = 2; i <= n; i++) {
        if(i <= M) continue;
        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 : a){
            if(s % to == 0 && !visit[to]){
                visit[to] = true;
                q.push(to);
                ans++;
            }
        }
        for(const int to : G[s]){
            if (visit[to]) { continue; }
            visit[to] = true;
            q.push(to);
            ans++;
        }
    }
    cout << ans << "\n";
    return 0;
}
0