結果
| 問題 | No.826 連絡網 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-23 16:37:02 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 896 bytes |
| 記録 | |
| コンパイル時間 | 807 ms |
| コンパイル使用メモリ | 71,680 KB |
| 実行使用メモリ | 116,096 KB |
| 最終ジャッジ日時 | 2024-11-24 02:13:12 |
| 合計ジャッジ時間 | 18,140 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 TLE * 2 |
ソースコード
#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 a[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);
}
}
int l = 0, r = 0;
a[r++] = p;
visit[p] = true;
int ans = 1;
while (r-l) {
const int s = a[l++];
for(int i = 2*s; i <= n; i += s){
if (visit[i]) { continue; }
visit[i] = true;
a[r++] = i;
ans++;
}
for(const int to : G[s]){
if (visit[to]) { continue; }
visit[to] = true;
a[r++] = to;
ans++;
}
}
cout << ans << "\n";
return 0;
}