結果
問題 | No.1737 One to N |
ユーザー |
![]() |
提出日時 | 2023-11-05 14:57:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 648 ms / 2,000 ms |
コード長 | 1,046 bytes |
コンパイル時間 | 1,321 ms |
コンパイル使用メモリ | 130,352 KB |
最終ジャッジ日時 | 2025-02-17 19:25:50 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#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();}