結果

問題 No.1737 One to N
ユーザー ゆにぽけゆにぽけ
提出日時 2023-11-05 14:57:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 587 ms / 2,000 ms
コード長 1,046 bytes
コンパイル時間 1,974 ms
コンパイル使用メモリ 135,556 KB
実行使用メモリ 82,688 KB
最終ジャッジ日時 2023-11-05 14:57:25
合計ジャッジ時間 21,295 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 546 ms
82,688 KB
testcase_01 AC 545 ms
82,688 KB
testcase_02 AC 567 ms
82,688 KB
testcase_03 AC 548 ms
82,688 KB
testcase_04 AC 570 ms
82,688 KB
testcase_05 AC 552 ms
82,688 KB
testcase_06 AC 587 ms
82,688 KB
testcase_07 AC 559 ms
82,688 KB
testcase_08 AC 557 ms
82,688 KB
testcase_09 AC 579 ms
82,688 KB
testcase_10 AC 550 ms
82,688 KB
testcase_11 AC 579 ms
82,688 KB
testcase_12 AC 545 ms
82,688 KB
testcase_13 AC 575 ms
82,688 KB
testcase_14 AC 543 ms
82,688 KB
testcase_15 AC 569 ms
82,688 KB
testcase_16 AC 545 ms
82,688 KB
testcase_17 AC 574 ms
82,688 KB
testcase_18 AC 538 ms
82,688 KB
testcase_19 AC 570 ms
82,688 KB
testcase_20 AC 542 ms
82,688 KB
testcase_21 AC 571 ms
82,688 KB
testcase_22 AC 547 ms
82,688 KB
testcase_23 AC 584 ms
82,688 KB
testcase_24 AC 556 ms
82,688 KB
testcase_25 AC 550 ms
82,688 KB
testcase_26 AC 571 ms
82,688 KB
testcase_27 AC 545 ms
82,688 KB
testcase_28 AC 562 ms
82,688 KB
testcase_29 AC 539 ms
82,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cassert>
#include<cmath>
#include<ctime>
#include<iomanip>
#include<numeric>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<random>
#include<functional>
#include<utility>
using namespace std;
const int M = (int)3e5;
vector<pair<int,int>> G[M+1];
long long dp[M+1];
void solve()
{
	for(int i = 1;i <= M;i++)
	{
		dp[i] = (long long)1e18;
		for(int j = i+i;j <= M;j += i) G[i].push_back(make_pair(j,j/i));
	}
	dp[1] = 0;
	priority_queue<pair<long long,int>> Q;
	Q.push(make_pair(-0LL,1));
	while(!Q.empty())
	{
		long long cur = -Q.top().first;
		int u = Q.top().second;
		Q.pop();
		if(dp[u] < cur) continue;
		for(auto &[v,c]:G[u]) if(dp[v] > dp[u]+c)
		{
			dp[v] = dp[u]+c;
			Q.push(make_pair(-dp[v],v));
		}
	}
	int N;
	cin >> N;
	cout << dp[N] << "\n";
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	/* cin >> tt; */
	while(tt--) solve();
}
0