結果

問題 No.1465 Archaea
ユーザー ks2mks2m
提出日時 2021-04-02 21:43:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 453 ms / 2,000 ms
コード長 753 bytes
コンパイル時間 4,329 ms
コンパイル使用メモリ 79,328 KB
実行使用メモリ 59,488 KB
最終ジャッジ日時 2023-08-25 16:11:23
合計ジャッジ時間 8,074 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,440 KB
testcase_01 AC 124 ms
55,544 KB
testcase_02 AC 125 ms
55,648 KB
testcase_03 AC 123 ms
55,680 KB
testcase_04 AC 124 ms
55,312 KB
testcase_05 AC 123 ms
56,124 KB
testcase_06 AC 125 ms
55,304 KB
testcase_07 AC 191 ms
56,144 KB
testcase_08 AC 127 ms
55,608 KB
testcase_09 AC 242 ms
56,480 KB
testcase_10 AC 126 ms
55,772 KB
testcase_11 AC 214 ms
58,480 KB
testcase_12 AC 124 ms
55,764 KB
testcase_13 AC 367 ms
58,320 KB
testcase_14 AC 220 ms
56,404 KB
testcase_15 AC 126 ms
56,012 KB
testcase_16 AC 125 ms
55,700 KB
testcase_17 AC 391 ms
58,408 KB
testcase_18 AC 128 ms
56,344 KB
testcase_19 AC 222 ms
56,536 KB
testcase_20 AC 313 ms
57,080 KB
testcase_21 AC 453 ms
58,964 KB
testcase_22 AC 446 ms
59,488 KB
testcase_23 AC 126 ms
55,840 KB
権限があれば一括ダウンロードができます

ソースコード

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