結果

問題 No.1465 Archaea
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2021-04-02 22:45:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,806 bytes
コンパイル時間 1,791 ms
コンパイル使用メモリ 178,292 KB
実行使用メモリ 14,964 KB
最終ジャッジ日時 2023-08-25 16:19:56
合計ジャッジ時間 2,864 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 7 ms
6,060 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 12 ms
7,604 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 10 ms
6,684 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 21 ms
11,908 KB
testcase_14 AC 9 ms
6,996 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 23 ms
12,656 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 10 ms
7,332 KB
testcase_20 AC 17 ms
10,168 KB
testcase_21 AC 28 ms
14,964 KB
testcase_22 AC 27 ms
14,908 KB
testcase_23 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2021.04.02 22:45:04
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;




template<typename T>
struct Dijkstra {
private:
    int V;
    struct edge { int to; T cost; };
    vector<vector<edge>> G;
public:
    const T inf = numeric_limits<T>::max();
    
    
    vector<T> d; 
    Dijkstra() {}
    Dijkstra(int V) : V(V) {
        G.resize(V);
    }
    
    Dijkstra<T>& operator=(const Dijkstra<T>& obj) {
        this->V = obj.V;
        this->G = obj.G;
        this->d = obj.d;
        return *this;
    }
    
    
    void add_edge(int from, int to, T weight, bool directed = false) {
        G[from].push_back({to,weight});
        if (!directed) G[to].push_back({from,weight});
    }
    
    
    int add_vertex() {
        G.push_back(vector<edge>());
        return V++;
    }
    void build(int s) {
        d.assign(V, inf); 
        typedef tuple<T, int> P; 
        
        queue<P> pq;
        d[s] = 0; 
        pq.push(P(d[s], s)); 
        while (!pq.empty()) {
            
            P p = pq.front(); pq.pop();
            int v = get<1>(p);
            
            if (d[v] < get<0>(p)) continue; 
            for (const edge &e : G[v])
            {
                
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    pq.push(P(d[e.to], e.to));
                }
            }
        }
    }
};
int main() {
    int n,k;cin >> n >> k;
    Dijkstra<int> g(n);
    for (int i = 1; i <= n; i++) {
        if (i * 2 <= n) g.add_edge(i-1,i*2-1,1,true);
        if (i + 3 <= n) g.add_edge(i-1,i+3-1,1,true);
    }
    g.build(0);
    if (g.d[n-1] <= k) {
        puts("YES");
    }
    else {
        puts("NO");
    }
    return 0;
}
0