結果

問題 No.683 Two Operations No.3
ユーザー matsuyoshi30matsuyoshi30
提出日時 2018-05-12 12:20:31
言語 Java19
(openjdk 21)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 737 bytes
コンパイル時間 2,069 ms
コンパイル使用メモリ 71,324 KB
実行使用メモリ 56,104 KB
最終ジャッジ日時 2023-09-10 18:47:18
合計ジャッジ時間 5,221 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,988 KB
testcase_01 AC 125 ms
55,848 KB
testcase_02 AC 125 ms
53,920 KB
testcase_03 AC 126 ms
55,868 KB
testcase_04 AC 127 ms
55,980 KB
testcase_05 AC 127 ms
55,744 KB
testcase_06 AC 124 ms
55,788 KB
testcase_07 AC 126 ms
55,840 KB
testcase_08 AC 125 ms
55,664 KB
testcase_09 AC 126 ms
55,804 KB
testcase_10 AC 126 ms
55,932 KB
testcase_11 AC 127 ms
55,604 KB
testcase_12 AC 127 ms
55,448 KB
testcase_13 AC 127 ms
55,816 KB
testcase_14 AC 125 ms
56,104 KB
testcase_15 AC 128 ms
55,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long a = in.nextLong();
        long b = in.nextLong();

        boolean ans = rec(a, b);
        if(ans)
            System.out.println("Yes");
        else
            System.out.println("No");
    }

    private static boolean rec(long i, long j) {
        if(i == 0 || j == 0) return true;

        if(i % 2 == 0 && j % 2 == 0)
            return rec(i / 2, j - 1) | rec(i - 1, j / 2);
        if(i % 2 == 1 && j % 2 == 1)
            return false;
        if(i % 2 == 1)
            return rec(i - 1, j / 2);
        if(j % 2 == 1)
            return rec(i / 2, j - 1);

        return false;
    }
}
0