結果

問題 No.1465 Archaea
ユーザー tentententen
提出日時 2021-11-29 20:18:00
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,889 bytes
コンパイル時間 2,154 ms
コンパイル使用メモリ 75,144 KB
実行使用メモリ 55,316 KB
最終ジャッジ日時 2023-09-15 09:20:40
合計ジャッジ時間 4,952 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,496 KB
testcase_01 WA -
testcase_02 AC 45 ms
49,672 KB
testcase_03 AC 44 ms
49,608 KB
testcase_04 AC 43 ms
49,612 KB
testcase_05 AC 44 ms
49,568 KB
testcase_06 AC 44 ms
49,548 KB
testcase_07 AC 86 ms
51,436 KB
testcase_08 AC 45 ms
49,412 KB
testcase_09 AC 86 ms
51,544 KB
testcase_10 WA -
testcase_11 AC 93 ms
52,356 KB
testcase_12 AC 48 ms
49,728 KB
testcase_13 AC 116 ms
54,556 KB
testcase_14 AC 98 ms
51,908 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 129 ms
54,976 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 148 ms
55,240 KB
testcase_22 AC 154 ms
55,316 KB
testcase_23 AC 44 ms
49,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] costs = new int[n + 1];
        Arrays.fill(costs, Integer.MAX_VALUE);
        PriorityQueue<Path> queue = new PriorityQueue<>();
        queue.add(new Path(0, 0));
        while (queue.size() > 0) {
            Path p = queue.poll();
            if (p.idx > n || p.value > k || costs[p.idx] <= p.value) {
                continue;
            }
            costs[p.idx] = p.value;
            queue.add(new Path(p.idx + 3, p.value + 1));
            queue.add(new Path(p.idx * 2, p.value + 1));
        }
        if (costs[n] > k) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
    
    static class Path implements Comparable<Path> {
        int idx;
        int value;
        
        public Path(int idx, int value) {
            this.idx = idx;
            this.value = value;
        }
        
        public int compareTo(Path another) {
            return value - another.value;
        }
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0