結果

問題 No.683 Two Operations No.3
ユーザー htensai
提出日時 2020-05-08 16:47:15
言語 Java
(openjdk 23)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 874 bytes
コンパイル時間 2,314 ms
コンパイル使用メモリ 79,728 KB
実行使用メモリ 41,652 KB
最終ジャッジ日時 2024-07-03 09:53:27
合計ジャッジ時間 4,744 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

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