結果

問題 No.1465 Archaea
ユーザー ks2m
提出日時 2021-04-02 21:43:05
言語 Java
(openjdk 23)
結果
AC  
実行時間 359 ms / 2,000 ms
コード長 753 bytes
コンパイル時間 2,050 ms
コンパイル使用メモリ 77,752 KB
実行使用メモリ 57,624 KB
最終ジャッジ日時 2024-12-24 01:11:07
合計ジャッジ時間 7,155 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static int[] a;
	static boolean[] b;
	static int inf = 1000000;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		sc.close();

		a = new int[n + 1];
		b = new boolean[n + 1];
		Arrays.fill(a, inf);
		a[1] = 0;
		b[1] = true;
		int res = dfs(n);
		if (res > k) {
			System.out.println("NO");
		} else {
			System.out.println("YES");
		}
	}

	static int dfs(int n) {
		if (b[n]) {
			return a[n];
		}
		b[n] = true;
		int ret = inf;
		if (n >= 4) {
			ret = Math.min(ret, dfs(n - 3) + 1);
		}
		if (n % 2 == 0) {
			ret = Math.min(ret, dfs(n / 2) + 1);
		}
		return a[n] = ret;
	}
}
0