結果
問題 | No.1465 Archaea |
ユーザー |
![]() |
提出日時 | 2021-04-02 21:40:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 977 bytes |
コンパイル時間 | 1,828 ms |
コンパイル使用メモリ | 176,104 KB |
実行使用メモリ | 15,344 KB |
最終ジャッジ日時 | 2024-12-24 01:10:48 |
合計ジャッジ時間 | 2,973 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 20 |
ソースコード
#include<bits/stdc++.h> using namespace std; int INF = 1000000000; int main() { int N,K; cin >> N >> K; vector<int>dist(N+1,INF); vector<vector<pair<int,int>>>road(N+1); for(int i = 1; i <= N; i++) { if(i*2 <= N) { road[i].push_back({i*2,1}); } if(i+3 <= N) { road[i].push_back({i+3,1}); } } priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>que; que.push({0,1}); dist[1] = 0; while (!que.empty()) { pair<int,int> x = que.top(); que.pop(); if(dist[x.second] < x.first) { continue; } for(auto i:road[x.second]) { if(dist[i.first] > x.first+i.second) { dist[i.first] = x.first+i.second; que.push({dist[i.first],i.first}); } } } if(dist[N] <= K) { cout << "YES" << endl; } else { cout << "NO" << endl; } }