結果
問題 | No.1465 Archaea |
ユーザー |
![]() |
提出日時 | 2021-04-02 22:52:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 90 ms / 2,000 ms |
コード長 | 1,308 bytes |
コンパイル時間 | 2,112 ms |
コンパイル使用メモリ | 205,744 KB |
最終ジャッジ日時 | 2025-01-20 09:55:12 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++) void dijkstra(vector<vector<pair<ll,ll>>> G, vector<ll> &d, ll srt){ priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> que; que.push({0, srt}); d[srt] = 0; while(!que.empty()){ auto q = que.top(); que.pop(); if(q.first > d[q.second]) continue; for(auto g : G[q.second]){ if(d[g.first] <= q.first + g.second) continue; d[g.first] = q.first + g.second; que.push({d[g.first], g.first}); } } } void dijkstra(vector<vector<ll>>& G, vector<ll> &d, ll srt) { ll n = G.size(); vector<vector<pair<ll,ll>>> P(n); rep(i, 0, n) { for(auto j : G[i]) P[i].push_back({j, 1}); } dijkstra(P, d, srt); } void solve() { ll n, k; cin >> n >> k; const ll inf = 1e18; vector<ll> dp(n+1, inf); vector<vector<ll>> G(n+1); rep(i, 1, n+1) { if(i+3 <= n) G[i].push_back(i+3); if(i*2 <= n) G[i].push_back(2*i); } dijkstra(G, dp, 1); if(dp[n] <= k) cout << "YES\n"; else cout << "NO\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }