結果

問題 No.826 連絡網
コンテスト
ユーザー kopricky
提出日時 2019-04-23 16:51:17
言語 C++14
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 788 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 529 ms
コンパイル使用メモリ 96,412 KB
実行使用メモリ 114,820 KB
最終ジャッジ日時 2026-10-14 23:34:05
合計ジャッジ時間 8,214 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2
other AC * 1 WA * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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