結果

問題 No.683 Two Operations No.3
ユーザー htensaihtensai
提出日時 2020-05-08 16:47:15
言語 Java19
(openjdk 21)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 874 bytes
コンパイル時間 2,121 ms
コンパイル使用メモリ 72,444 KB
実行使用メモリ 55,904 KB
最終ジャッジ日時 2023-09-16 08:30:32
合計ジャッジ時間 5,182 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
55,452 KB
testcase_01 AC 127 ms
55,440 KB
testcase_02 AC 128 ms
55,612 KB
testcase_03 AC 130 ms
55,652 KB
testcase_04 AC 129 ms
55,456 KB
testcase_05 AC 128 ms
55,904 KB
testcase_06 AC 131 ms
55,464 KB
testcase_07 AC 132 ms
55,560 KB
testcase_08 AC 129 ms
55,500 KB
testcase_09 AC 130 ms
55,576 KB
testcase_10 AC 128 ms
55,192 KB
testcase_11 AC 127 ms
55,132 KB
testcase_12 AC 129 ms
55,496 KB
testcase_13 AC 129 ms
55,820 KB
testcase_14 AC 128 ms
55,452 KB
testcase_15 AC 129 ms
55,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		if (check(sc.nextLong(), sc.nextLong())) {
		    System.out.println("Yes");
		} else {
		    System.out.println("No");
		}
	}
	
	static boolean check(long a, long b) {
	    if (a == 0) {
	        return true;
	    }
	    if (a < 0 || b < 0) {
	        return false;
	    }
	    if (a > b) {
	        return check(b, a);
	    }
	    if (a % 2 == 0) {
	        if (b % 2 == 0) {
	            if (check(a / 2, b - 1)) {
	                return true;
	            } else {
	                return check(a - 1, b / 2);
	            }
	        } else {
	            return check(a / 2, b - 1);
	        }
	    } else {
	        if (b % 2 == 0) {
	            return check(a - 1, b / 2);
	        } else {
	            return false;
	        }
	    }
	}
}
0